How to stop a sprite
Root / Programming Questions / [.]
zagg2000Created:
Just make a small program Stoping a controlled sprite from moving when it hits any angle of a layer of the map.i can't exactly get to your codeif its so easy, do it yourself!i got the BGCOL Down, but i need the code on how to stop my moving sprite when it hits all directions of a map layer.just add an IF, dude.
too busy; give me a codebaseJust make a small program Stoping a controlled sprite from moving when it hits any angle of a layer of the map.i can't exactly get to your codeif its so easy, do it yourself!i got the BGCOL Down, but i need the code on how to stop my moving sprite when it hits all directions of a map layer.just add an IF, dude.
the... map boundaries?i mean like, when my main player sprite hits an object on layer 2 of my map, it'll stop the sprite from moving in the direction the object in layer 2 is in. so like, if my sprit is moving towards the object, my SP stops from going thorough it.X = max(min(X,maximum),0) Y = max(min(Y,maximum),0)
How to stop a sprite: have you tried not moving it?
At some point in your code, I'm assuming you calculate by how many pixels the player moves in the X direction, and by how many pixels the player moves in the Y direction. Put these calculations into variables, say DELTAX and DELTAY. BEFORE you update the player's position, use BGGET(layer, PLAYERX+DELTAX, PLAYERY+DELTAY, 1) to check if that is a forbidden region. If you find out that it is a forbidden region, set both DELTAX and DELTAY to zero. After you do this check, add DELTAX and DELTAY to your player's position. You stop the sprite by... not moving it.
This is rather strict, though. As an alternative, if you find (PLAYERX+DELTAX, PLAYERY+DELTAY) is blocked, you could be more sophisticated. You could check if (PLAYERX+DELTAX, PLAYERY) is a forbidden region - if it's not, allow the user to 'slide' along the edge of the forbidden region by setting DELTAY to zero and leaving DELTAX alone. If (PLAYERX+DELTAX, PLAYERY) is forbidden, check (PLAYERX, PLAYERY+DELTAY), and allow sliding along the vertical edge if that's possible there. If all three tests show forbidden region, don't allow movement at all.
For future reference, if you want help, it's in your best interest as well as everyone else's if you make it easier for people to help you, rather than harder, and use the resources available responsibly.
Is it too complicated to take one sentence at a time?
At some point in your code, I'm assuming you calculate by how many pixels the player moves in the X direction, and by how many pixels the player moves in the Y direction.Is this true? Can you identify that point in your code?