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

Changing the sprite but keeping the image_index for the new sprite

Discussion in 'Programming' started by Zuljaras, May 2, 2019.

  1. Zuljaras

    Zuljaras Member

    Joined:
    Jan 16, 2017
    Posts:
    414
    I have the following scenario.

    I have arrack animation while on the ground and attack animation while in the air.

    I want to be able to change my sprite from the air one to the ground one but keep the animation where it left off.

    While I am in the air I have the sprite index to change from player_attack_air to player_fall while there is no solid ground beneath the player.
    However if there is solid ground beneath the player and he is still in his air_attack animation I want him to change to his ground attack animation but start from the last image_index he was in the air attack sprite.

    I have the following code for the moment:
    Code:
    if sprite_index == playersattackright_air
        {
            im = image_index;
        }
    
    if sprite_index==playersattackright_air && !place_free(x,y+vspeed) && sprite_index != playersattackright
        {   
            sprite_index = playersattackright;
            image_index = im;
            image_speed = 0.3;
        }
     
  2. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,925
    What is the problem you're facing with this?
    What behavior are you expecting?
    What happens instead?
     
  3. Zuljaras

    Zuljaras Member

    Joined:
    Jan 16, 2017
    Posts:
    414
    I just saw that I am placing this in the step event instead of the end_step event.

    The problem was that the synch of both sprites was not ok.
    the new one was playing from image_index 0. Not from "im".
     

Share This Page