Page 1 of 1

[Tutorial]: Blinking

PostPosted: Thu Jan 26, 2012 9:37 am
by Leif
This tutorial is to answer on two questions:
1. How make actor blink without making additional animation frames ?
2. How make text actor blink? Text actors can not have animation at all...

Well, it's simple. First, let's see how to play with transparency.
All you have to do is to insert following code into actors "Draw Actor" function

Code: Select all
double  Base;        // base value of transparency, between  0..1
int     Frequency;   // Frequency of blinking, must be >1
double  Amplitude;  // how much trancparency will change.

// of cause you can declare these variables in global code instead of local procedure
// Normally:
// Base+Amplitude<=1
// Base-Amplitude>=0
 
Base=0.5; 
Frequency=8;
Amplitude=0.5;

transp=1-(Base+cos(degtorad(frame)*Frequency)*Amplitude);


Actor will blink.
As you can see, all based on cos function. Changing Base, Frequency, Amplitude values you can adjust your actor's blinking.
Note, that
Code: Select all
transp=1-(Base+cos(degtorad(frame)*Frequency)*Amplitude)
string is for initial transparence 0;
Code
Code: Select all
transp=Base+cos(degtorad(frame)*Frequency)*Amplitude;
string is for initial transparence 1;

The second case is "color-changing" blinking. In this case we have to work with r,g,b values of actor. Insert into "Draw Actor" function next code:

Code: Select all
int  Base_R,Base_G,Base_B;       // base value of transparency, between  0..255
int  Frequency_R,Frequency_G,Frequency_B;  // Frequency of blinking, must be >1
int  Amplitude_R,Amplitude_G,Amplitude_B;  // how much value will change.

// Normally:
// Base+Amplitude<=255
// Base-Amplitude>=0
 
 
Base_R=128;
 Base_G=128;
  Base_B=128;
 
Frequency_R=16;
 Frequency_G=16;
  Frequency_B=16;

Amplitude_R=128;
 Amplitude_G=128;
  Amplitude_B=128;

r=Base_R+cos(degtorad(frame)*Frequency_R)*Amplitude_R;
g=Base_G+cos(degtorad(frame)*Frequency_G)*Amplitude_G;
b=Base_B+cos(degtorad(frame)*Frequency_B)*Amplitude_B;


Actor will fade to black and return to normal condition again and again.
Changing initial values of variables will help you to get different effects

Have fun ! :D

Re: [Tutorial]: Blinking

PostPosted: Thu Jan 26, 2012 1:59 pm
by CoFFiN6
Thanx Leif. In your code..
Code: Select all
transp=1-(Base+cos
(degtorad
(frame)*Frequency)*Amplitude);

What does the "(frame)" mean?

Re: [Tutorial]: Blinking

PostPosted: Thu Jan 26, 2012 4:04 pm
by Leif
frame: Game frame count. This variable is global and read only.


See here http://game-editor.com/docs/script_reference.htm

It means, that game counts all frames. And we can use it.

Re: [Tutorial]: Blinking

PostPosted: Thu Jan 26, 2012 5:06 pm
by Hblade
Excellent :)

Re: [Tutorial]: Blinking

PostPosted: Sat Jan 28, 2012 9:58 pm
by CoFFiN6
Ah thank ya