How do you control opacity with scripts?

how does i control opactiy with scripts?? aswell the whole text script thing really confused what to use with them

Hi @Tsake,

You can change the opacity of an object by writing

objectName.opacity = 0.1; 

The value you set opacity to must be between 0 and 1 where 0 is invisible and 1 is completely opaque.

Here’s a script that changes the opacity of an object over time. (Change objectName to the name of the object)

function update() {
  objectName.opacity = objectName.opacity - .01;
}

Let me know if this helps!

2 Likes

thanks! this cleared up all the questions :D

1 Like

I elaborated somewhat on this:

this.opacity = 0
sq = this
var callCount = 1;

var repeater = setInterval(function () {
if (callCount < 20) {
    sq.opacity = sq.opacity +.1
    callCount += 1;
} else {
    clearInterval(repeater);
}
}, 250);

This can be used in a object, and will, in 20 steps / 5 seconds, fade to full transparency…
Works like a charm :slight_smile:

regards,

Paul

In a follow up: I use this script to have an object blink in and out of visibility to 3 times, all in one frame:

objBlink = Blinker
objBlink.opacity = 0 

counter = 0
frmPauze = this

function update(){
    if (counter % 2 == 1){
        objBlink.opacity = 0;
    }else{
        objBlink.opacity = 1;    
    }
    
    counter++
    if (counter < 10 )
        setTimeout( update , 500)
    else
        frmPauze.play()
}

setTimeout( update , 500)

The object is named, not very originally, Blinker. this code will show/hide it 5 times, and then carry on with the timeline. As I use this in my animations to draw attention to a object (for instance with an outline!) I use this often. Just thought I’d share :slight_smile:

Regards,

Paul

Hello! Which tab should the code be typed in? Mouse, Keyboard, or Timeline?

It depends on when you want the script to fire up.
If you want the opacity to be (0.5) when the mouse is pressed then use the mousePressed script or if you want the script to be fired when a key is pressed use keyPressed. It’s up to you!
If you want the script to be fired before any script does, you can use the default script.

1 Like