Touch screen collision is no different than top screen collision lol
Touch Screen Collision?
Root / Programming Questions / [.]
ProKukuCreated:
In my program I’m controlling a sprite using the touch screen, and I’m trying to implement collision with map tiles and that sprite. I use BGGET to tell when the sprite is actually colliding with the tiles, but I don’t know how I could make it so that the sprite doesn’t go through those tiles.
When I say “implement collision” I mean the sprite bumping into a tile and stopping at a certain point instead of going through the tile.
You may want to store the sprite coordinates when the program first detects a collision and not allow the sprite to move past those coordinates.
Perhaps you could check the touch coordinates themselves. If the touch falls into a region of "on or inside something solid," then don't move the sprite there. If they're not inside something, then move the sprite to the touch coordinates.
Touch screen collision is no different than top screen collision lolIt's a lot different when moving a sprite with the stylus instead of a predictable d-pad or circle pad.
You may want to store the sprite coordinates when the program first detects a collision and not allow the sprite to move past those coordinates. Perhaps you could check the touch coordinates themselves. If the touch falls into a region of "on or inside something solid," then don't move the sprite there. If they're not inside something, then move the sprite to the touch coordinates.I did have a similar idea of saving the position of the sprite when it collided with a wall, and not letting it move past that point, but it got very buggy when I tried adding more than one side of collision detection. The second idea definitely wouldn't work, because I have a lot of tiles to collide with.
@ProKuku Do these tiles fall into a fixed position grid (are they all aligned)? Do these tiles on the lower screen move or are they fixed? If the first is true, my second suggestion may be the best for either case, movement or not, really. There are ways of determining what tile a certain X-Y coordinate is on without having to run through every single tile.