• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM how to switch sprite_index but not forever

  • Thread starter SonicTheHedgehog+123
  • Start date
S

SonicTheHedgehog+123

Guest
The Problem that I have is that when I am switching from my player_sprite to my ducking sprite. I cant change to another sprite because the code is in the step event.
Here is the ducking code:

if keyboard_check(ord("S"))
{
sprite_index = Ducken
}
else
{
sprite_index = Fledermaus_Bild
}
if sprite_index = Ducken
{
hspeed = 0
}


is there a way that my sprite goes from ducking to player sprite and I still can switch to other sprites (like an item_sprite)

Open for any help:D
 
J

Jordan Robinson

Guest
After you set the player sprite, you can just add more if else statements for the other sprites you wish to change to
 
S

SonicTheHedgehog+123

Guest
Thank you for replying
It didnt work.
I have multiple items in my game and whenever I am touching one it should change to the item sprite.
However the sprite changes for an instant to the item sprite and then goes again to the player sprite.
Why does the duck code have priority over the item code?
I did watch shaun spaldings video about power ups. Here is the code of one of my power ups:
Code:
//PowerUp collision with player
with (Fledermaus)
{
room_speed = 30;
sprite_index = Fledermaus_PowerUp;
image_speed = 1/3;
alarm[4] = 300;
}
instance_destroy()[/B]
 
It doesn't have priority, you're just not seeing the logic behind the code. The ducking code, being in the Step event, runs every frame, so as long as you're holding S, the sprite is set to duck. If you collide with the PowerUp, the player's sprite index changes, and then the PowerUp is immediately destroyed. Now, with it no longer existing to continually run that collision event, on the next frame, there is no event to execute, but the player's Step event is naturally still running. S is still held down, and the sprite changes.

You have to really think about your whole sprite structure from the ground up, factoring in whatever external influences that may exist.
 
S

SonicTheHedgehog+123

Guest
Now I understand. I really must learn the algorithm of GML.
That also means that the sprite should only change if the alarm reaches zero.
I will find a solution to this.Thank you for explaining my mistake:D
 
Top