GMS 2 Make a object 'blink'

Discussion in 'Programming' started by Bokkie2988, Oct 7, 2019.

  1. Bokkie2988

    Bokkie2988 Member

    Joined:
    Aug 3, 2018
    Posts:
    71
    Hey,

    As the title says. How would I make a object blink with image_alpha?

    -Bokkie
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,556
    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;
    
     
    Bentley likes this.
  3. TheSly

    TheSly Member

    Joined:
    Jan 16, 2017
    Posts:
    990
    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: Oct 8, 2019
  4. Bokkie2988

    Bokkie2988 Member

    Joined:
    Aug 3, 2018
    Posts:
    71
    Is this a smooth transition btw? Because I need that
     
  5. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,556
    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);
    
     
  6. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,742
    Even simpler: in Step event, put
    image_alpha = 0.5 + lengthdir_x(0.5,current_time*0.25)
     
    Bentley likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice