Im making a top down rpg and want to know how to change the player sprite whent moving foward, back etc
Hello there!
This is actually fairly simple! You will need 4 player sprites: one for facing up, one for facing down, one for facing left, and one for facing right. Then, you'll need to put some code in the update function in your player script.
if event.dx==1 then
swap "playerRight"
elseif event.dx==-1 then
swap "playerLeft"
elseif event.dy==1 then
swap "playerFront"
elseif event.dy==-1 then
swap "playerBack"
end
You'll just need to replace all the swap "player"
with the name of your own sprite.
Hope this helps!
An even cleaner method (albeit a little more advanced) is using frames. This sacrifices animations, but is worth the de-cluttering.
on update do
if event.dx==1 then
frame 0
elseif event.dx==-1 then
frame 1
elseif event.dy==1 then
frame 2
elseif event.dy==-1 then
frame 3
end
end
Note that these are zero-based, so frame one is frame 0.
Yeah, that's a great suggestion! I've never thought about using frames for that purpose! I always just made separate sprites, even though I use frames for everything else. The only downside is that then you cannot animate the player sprite, but as long as you aren't doing that, frames would be better!