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

How to make a sprite stop in place when it detects a bg tile next to it...

Root / Programming Questions / [.]

DefaultioCreated:
Like what the name says, I used BGCOORD to convert the sprites coordinates into BG tile Coordinates, then used BGGET to make it check directly under the sprite for bg tiles. It works but, I want it so that when BGGET detects specific tiles, its halts the sprites movement (ex. Left, Right, Up, Down). How do I do it?

Are you trying to use the BGGET to get the tile value to determine what kind of collision is needed? You could use an array containing the id numbers of tiles that collide and once you BGGET a tile, iterate through that array to determine if it's one of them. This would be a kind of manual process though. The other thing you could do is if you aren't using all of your bg layers, one of them could contain collision data. In the map editor in the smile tool, you could just paint where you want collision. You wouldn't display the layer in your game, just check it with BGGET, and then if the tile is anything other than 0, it's a collision. The second part of your question, is that your character movement should always get calculated. When the user presses left, you add the left movement velocity to the sprite, but store the old position first. If your character is only moving a pixel at a time, you can just revert to the old position if the new position causes a collision. It's more complicated if you're moving faster than that, but let me know if I've understood the problem correctly.

The second part of your question, is that your character movement should always get calculated. When the user presses left, you add the left movement velocity to the sprite, but store the old position first. If your character is only moving a pixel at a time, you can just revert to the old position if the new position causes a collision. It's more complicated if you're moving faster than that, but let me know if I've understood the problem correctly.
I just want the character to stop movjng a certain direction when it tocuhes a bgtile, I already know how to set up collision, just not get it working right.

Sorry I'm just thinking about the theory but could you just manually code each position? I'm assuming this is like grid movement? So for each BG tile it detects, it sets SPOFS to that position and locks it in until the next input.

Sorry I'm just thinking about the theory but could you just manually code each position? I'm assuming this is like grid movement? So for each BG tile it detects, it sets SPOFS to that position and locks it in until the next input.
Yes exactly like that.

how?