[Tutorial]: Blinking

Learn how to make certain types of games and use gameEditor.

[Tutorial]: Blinking

Postby Leif » Thu Jan 26, 2012 9:37 am

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
Attachments
Blinking Tutorial.zip
(1.7 KiB) Downloaded 169 times
Last edited by Leif on Thu Jan 26, 2012 5:22 pm, edited 1 time in total.
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: [Tutorial]: Blinking

Postby CoFFiN6 » Thu Jan 26, 2012 1:59 pm

Thanx Leif. In your code..
Code: Select all
transp=1-(Base+cos
(degtorad
(frame)*Frequency)*Amplitude);

What does the "(frame)" mean?
Don't run faster then the dragon, run faster than your friends :P
User avatar
CoFFiN6
 
Posts: 49
Joined: Sun Sep 11, 2011 8:17 pm
Location: South Africa
Score: 4 Give a positive score

Re: [Tutorial]: Blinking

Postby Leif » Thu Jan 26, 2012 4:04 pm

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.
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: [Tutorial]: Blinking

Postby Hblade » Thu Jan 26, 2012 5:06 pm

Excellent :)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: [Tutorial]: Blinking

Postby CoFFiN6 » Sat Jan 28, 2012 9:58 pm

Ah thank ya
Don't run faster then the dragon, run faster than your friends :P
User avatar
CoFFiN6
 
Posts: 49
Joined: Sun Sep 11, 2011 8:17 pm
Location: South Africa
Score: 4 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron