• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Make a object 'blink'

FrostyCat

Member
Do people not learn how to use alarms and variables as part of their GML training anymore?

Create:
Code:
blink = true;
alarm[0] = 0.5*room_speed;
Alarm 0:
Code:
blink = !blink;
image_alpha = blink ? 1 : 0.25;
alarm[0] = 0.5*room_speed;
 

Slyddar

Member
You could also do it without an alarm like this:

CREATE
Code:
blink_time = 0;
blink_length = 30;
blink_alpha = 0.25;
STEP:
Code:
//set image_alpha
if blink_time++ > blink_length image_alpha = blink_alpha else image_alpha = 1;

//reset time
if blink_time > blink_length * 2 blink_time = 0;
 
Last edited:

Bokkie2988

Member
You could also do it without an alarm like this:

CREATE
Code:
blink_time = 0;
blink_length = 30;
blink_alpha = 0.25;
STEP:
Code:
//set image_alpha
if blink_time++ > blink_length image_alpha = blink_alpha else image_alpha = 1;

//reset time
if blink_time > blink_length * 2 blink_time = 0;
Is this a smooth transition btw? Because I need that
 

FrostyCat

Member
Is this a smooth transition btw? Because I need that
If you wanted a smooth transition, you should have said that from the start, not after you get a response.

Create:
Code:
blink_theta = 0;
blink_theta_rate = 4;
Step:
Code:
blink_theta = (blink_theta+blink_theta_rate) mod 360;
image_alpha = 0.5*(dcos(blink_theta)+1);
 

Yal

šŸ§ *penguin noises*
GMC Elder
Even simpler: in Step event, put
image_alpha = 0.5 + lengthdir_x(0.5,current_time*0.25)
 
Top