Player Direction?

Sorry for such a basic question, but I'm struggling to figure out how to make my player change direction as it moves.

I've created four frames for the player facing the cardinal directions, and have set the fps to 0 so it's not constantly spinning, but I'm not sure where to go from here. There's no function I can see for "on {arrow press}", so I'm not sure how to tell pulp to respond to directional buttons being pressed and change the frame accordingly to the proper direction.

4 Likes

It's not that basic unfortunatly.

In the players on update do function you need some if statements to check event.dx.


		// face left
		if event.dx==-1 then
			//do something like a  tile swap.
 
			// face right
		elseif event.dx==1 then
//do another tile swap, function or whatever
		end
		
	end

"dx" is a predefined check for "direction x" inside the event call. It's only ever 1 or -1

2 Likes

Use the event.dy and event.dx Values to determine what button was pressed by the player. Will be either positive or negative 1 depending on if up/down/left/right was pressed on the d-pad.

1 Like

That helps, thank you! I didn't realise I needed to use different tiles for the player rather than asking Pulp to call a different frame. That probably is possible, but I don't know how and this works just fine!

You can def set different frames for the player rather than swapping tiles. Just depends on whether or not you want to animate your player as it faces different directions or just show a static image.

If you're going the route of showing a static frame for each direction, you can just use a single player tile with the FPS set to 0. Then, instead of swapping the tile, call frame [frame #] from the player script to display a different frame (note that it's a 0-based index).

2 Likes

you can call "frame X" instead of swap there, that works fine to :slight_smile:

^ This - exactly spot on

Is the command line just
on update do
if event.dx==-1 then
frame [frame 0]

//the elseif and rest of it//

Because I'm getting told the frame statement is invalid

Sorry @AdamHopeless, the frame # shouldn't be in brackets.

Use something like:

on update do
    if event.dx==-1 then
       frame 0
    end
end
1 Like

Right, that works.

Thank you! My understanding of pulpscript is so basic I get imposter syndrome even using the world understanding

Thanks for the help :slight_smile: :grinning:

2 Likes