LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

How to stop a sprite

Root / Programming Questions / [.]

zagg2000Created:
Heres a code to what needs the help. MKXKNX3M Please stop my player from going through layer 2 & 3

you mean collision?

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.

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.
if 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.
if its so easy, do it yourself!
i can't exactly get to your code

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.
if its so easy, do it yourself!
i can't exactly get to your code
Just make a small program Stoping a controlled sprite from moving when it hits any angle of a layer of the map.

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.
if its so easy, do it yourself!
i can't exactly get to your code
Just make a small program Stoping a controlled sprite from moving when it hits any angle of a layer of the map.
too busy; give me a codebase

the... map boundaries?
X = max(min(X,maximum),0)
Y = max(min(Y,maximum),0)

the... map boundaries?
X = max(min(X,maximum),0)
Y = max(min(Y,maximum),0)
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.

in all directions the SP hits.

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.
if its so easy, do it yourself!
i can't exactly get to your code
Here. look at the Forum Description.

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.

So complicated :'[

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?