Do you want it to fade? If so, you can do this:
default script:
this.targetOpacity = 0
update script:
var opacityChangeRate = 2 / project.framerate; //should go to 100% opacity in 2 seconds.
if (this.opacity !== this.targetOpacity) {
var opacityChangeDir = Math.sign(this.targetOpacity - this.opacity);
this.opacity += opacityChangeDir * opacityChangeRate
//make sure it doesn't go past target opacity
if (
(opacityChangeDir > 0 && this.opacity > this.targetOpacity) || //increasing
(opacityChangeDir < 0 && this.opacity < this.targetOpacity) //decreasing
) {
this.opacity = this.targetOpacity;
}
}
keydown script:
if (key === "f") this.targetOpacity = 1;
//if your if statement includes only one command, you can omit the curly braces
Or you can use the setTimeout function to do this
keydown script:
var opacityChangeRate = 2 / project.framerate; //should go to 100% opacity in 2 seconds
var timeoutLength = 1000 / project.framerate; //framerate in milliseconds (60 fps turns into one frame per 16.6666666 milliseconds)
if (key === "f") {
var f = function() { //create a local function for recursion with setTimeout
this.opacity += opacityChangeRate;
if (this.opacity >= 1) this.opacity = 1;
else setTimeout(f, timeoutLength);
}
f();
}
I didn’t actually test these myself but hopefully they should work.