1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Fade sprites

Discussion in 'Programming' started by Sk8dududu, May 19, 2019.

  1. Sk8dududu

    Sk8dududu Member

    Joined:
    Aug 14, 2017
    Posts:
    200
    This is embarrassing, but I cannot waste anymore time on this. I absolutely have no idea why this isn't working, especially since I copied this code from another project that I have and it works fine there.

    I am using a controller to draw sprites during the intro of the game. The sprite fades in but I cannot get it to fade out. I've even checked the image alpha to see the number go down, it reaches zero but the sprite is visibly unchanged.

    Create event
    Code:
    ///Variables
    intro = 0;
    fade_alpha = 0;
    //Logo fade in alarm
    alarm_set(0,30);
    //Logo fade out alarm
    alarm_set(1,120);
    
    Alarm 1
    Code:
    ///Logo fade in
    intro = 1;
    
    Alarm 2
    Code:
    intro = 2;
    
    draw event
    Code:
    if intro == 1
        {
        draw_sprite_ext(spr_intro6,0,room_width/2,room_height/2,1,1,0,c_white,fade_alpha);
        if fade_alpha < 1
            {
            fade_alpha += 0.005;
            }
        }
    else if intro == 2
        {
        draw_sprite_ext(spr_intro6,0,room_width/2,room_height/2,1,1,0,c_white,fade_alpha);
        if fade_alpha > 0
            {
            fade_alpha -= 0.005;
            }
        }
    
    It's so simple but my brain cannot understand the issue.
     
  2. _Proxy

    _Proxy Member

    Joined:
    Jun 22, 2018
    Posts:
    16
    the code I use for fade in and fade out looks something like this
    Code:
    if (increase_alpha == true)
    {
        alpha += 0.05;
        if (alpha >= 1)
        {
            alpha = 1;
        }
    }
    
    if (decrease_alpha == true)
    {
        alpha -= 0.05;
        if (alpha <= 0)
        {
            alpha = 0;
        }
    }
    
     
  3. Sk8dududu

    Sk8dududu Member

    Joined:
    Aug 14, 2017
    Posts:
    200
    Yes, and that looks exactly the same to me so I don't understand why mine isn't fading out.
     
  4. _Proxy

    _Proxy Member

    Joined:
    Jun 22, 2018
    Posts:
    16
    ok this is what I do
    Code:
    // Create Event
    increase_alpha = true;
    decrease_alpha = false;
    
    // Step Event
    if (keyboard_check_pressed(ord("S"))
    {
        increase_alpha = false;
        decrease_alpha = true;
    }
    
    if (increase_alpha == true)
    {
        alpha += 0.05;
        if (alpha >= 1)
        {
            alpha = 1;
        }
    }
    
    if (decrease_alpha == true)
    {
        alpha -= 0.05;
        if (alpha <= 0)
        {
            alpha = 0;
        }
    }
    you can see in my code that I have something triggering the decrease of the alpha by setting the decrease_alpha equal to true and the increase_alpha to false.

    look at my video on counters as well instead of alarms: if you want the counter to only happen once instead of looping remove the counter = 0; in the step event
     
  5. Sk8dududu

    Sk8dududu Member

    Joined:
    Aug 14, 2017
    Posts:
    200
    I can't use image_alpha or alpha as you call it because my object has no sprite. It's drawing multiple sprites.
    I am switching the alpha increase and decrease to true at different points which I have verified is working using debug messages. I appreciate the attempted assistance but the alarms are not the issue because the alarms are activating.
     
  6. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    831
    Is there an instance of the intro object in the room that has a sprite?
     
  7. Sk8dududu

    Sk8dududu Member

    Joined:
    Aug 14, 2017
    Posts:
    200
    I actually solved the issue, but forgot to come back and say how.
    My room settings didn't have draw the background colour checked. So without any background or drawing a colour, it was drawing the sprites like every frame and keeping them there.
     

Share This Page