2

I am making a maze game in game maker v1.4.1763, and need some help changing a objects sprite based on its direction of movement. I am currently have an object following the mouse using game makers drag and drop 'move towards" action. I have sprites that are animated for the object from 4 different perspectives(front, back, left, and right.) The object can move in any direction (It doesn't have to stick to the cardinal directions.)

I want the object to change its sprite based on witch way it is "mostly" moving. I don't really know how to program using game makers language, but I know how to get it to execute code. I have tried almost everything using the drag and drop coding and this can only be accomplished using some code. If someone could help me come up with that code, that would be awesome.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Liam Bess
  • 21
  • 1
  • 2

1 Answers1

2

Simplest way:

if direction > 45 and direction <= 135 and sprite_index != spr_up
    sprite_index = spr_up;
else if direction > 135 and direction <= 225 and sprite_index != spr_left
    sprite_index = spr_left;
else if direction > 225 and direction <= 315 and sprite_index != spr_down
    sprite_index = spr_down;
else if sprite_index != spr_right
    sprite_index = spr_right;

Where spr_left, spr_right, spr_up, spr_down is your sprites. You can place this code in Step End event.

Dmi7ry
  • 1,777
  • 1
  • 13
  • 25