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

Changing player sprite with player direction

TRP

Member
Greetings,

Looking for help with an issue I'm having. I'm using touch or global left mouse button to move the player around. I also want the player sprite to change when I go right and down. I'm using the below code in the step event.

//sprite change player movement

if obj_player.direction=180
{
draw_sprite(player_flip, 0, x, y)
}

if obj_player.direction=270
{
draw_sprite(player_flip, 0, x, y)

This doesn't work...wondering if I'm even on the right track...

Thanks for your time,
 
D

Danei

Guest
draw functions should go in the draw event.

Also remember to draw_self() or something equivalent; instances do that automatically when they have no draw event code, but if you add stuff in there you'll have to do it manually.
 
Last edited by a moderator:
D

DaMuffin

Guest
Your code looks like it will check if the direction is exactly 180 or 270. I could be wrong, but if you're using the mouse to change direction then it'll be highly unlikely that you'll get those exact numbers. Try something like
Code:
if (obj_player.direction > 179) && (obj_player.direction < 271)
{
  draw_sprite(player_flip,0,x,y);
}
Hope that helps.
 

Calvert

Member
I would use draw_sprite_ext as it avoids collision issues in the future.

STEP EVENT:
Code:
angle = point_direction(x,y,mouse_x,mouse_y);
DRAW EVENT:
Code:
draw_sprite_ext(spr_player, 0, x, y, 1, 1, angle, c_white, 1);
 
Top