Player Tile Swap

Hey there!

I was attempting a player swap so the player sprite changes based on the direction input. I created the following script, but the sprite only changes when going up and stays that way.

on update do
if event.dy==-1 then
swap "player_up"
if event.dy==1 then
swap "test"
if event.dx==-1 then
swap "player_right"
if event.dx==1 then
swap "player_left"
end
end
end

end
end

Thank you in advance!

Your if statements are nested, so they don't check for all the conditions in sequence. What you want is something like,

on update do

 if event.dy==-1 then
  swap “player_up”
 elseif event.dy==1 then
  swap “test”
 end

 if event.dx==-1 then
  swap “player_right”
 elseif event.dx==1 then
  swap “player_left”
 end

end

This post includes a demo game that shows how I handle this behavior, btw: Pulp how-to: two-tile-tall player - #3 by Guv_Bubbs

That make sense.

Thanks for the help!