• 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!

How to Make Objects Sprite Change as it follows

A

Arj72

Guest
I am making a boss enemy in a platformer, where the enemy shoots off rockets and they follow the player. I want the sprite of the rocket to change depending on the direction it is going, but I have no clue how to. I tried this:

if vspeed > 0 while hspeed < 0
{sprite_index = Spr_RocketDownLeft}
else
if vspeed > 0 while hspeed > 0
{sprite_index = Spr_RocketDownRight}
else
if vspeed < 0 while hspeed < 0
{sprite_index = Spr_RocketUpLeft}
else
if vspeed < 0 while hspeed > 0
{sprite_index = Spr_RocketUpRight}

But the sprite doesn't change and if it does it stays like that forever. How can I make it change based upon the direction it is going?
 
the while() function is a loop, whereas the if() statement is a conditional/truth check. They won't work together the way you have them as you have written above.

Please check the manual for those two functions to read more about them.

In the meantime, what you can do is just have the one sprite Spr_RocketRight for example, and to set the angle of the rocket, just use:

image_angle = direction

As it looks like you are not using the built in variables, you may need to do something like this instead:

Code:
var my_dir = point_direction(0, 0, hspeed, vspeed)
image_angle = my_dir
 
Top