Check sprite collision with other sprite - Printable Version +- Tilengine - The 2D retro graphics engine forum (http://tilengine.org/forum) +-- Forum: English forums (http://tilengine.org/forum/forumdisplay.php?fid=3) +--- Forum: Support (http://tilengine.org/forum/forumdisplay.php?fid=7) +--- Thread: Check sprite collision with other sprite (/showthread.php?tid=1106) |
Check sprite collision with other sprite - Midnight Syntax - 05-03-2021 How would i go about checking collision with another sprite? I know I can get if a sprite is colliding with anything but how do I check if it's a tilemap or sprite? And if it's a sprite how could I check which specific sprite? RE: Check sprite collision with other sprite - megamarc - 05-05-2021 Hi, Sprite collisions -with both tiles and other sprites- is a gameplay mechanics topic. As Tilengine is a graphics engine, not a full game engine, it won't directly solve collisions. However it will assist you in implementing the suitable kind of collisions required by your game. Common way to deal with collisions is with so called "Axis-Aligned Bounding Box" -or AABB for short-. It consists on surrounding your objects inside rectangles, and check relative positions of these rectangles. When they overlap, there's a collision. Here's a great in-depth article on this subject: http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/ vs Sprite AABB is fast but it can be imprecise, depending on the sizes of the "hitbox" relative to the sprite graphic and the distribution of transparent pixels, you can have false positives -detect a collision where no actual pixels are colliding- or false negatives -missing an actual collision-. For many games this is just ok, but if you need extra precision, Tilengine supports pixel accurate collision detection. Just as real 2D video processors, it will tell if a given sprite is colliding with another on a per-pixel basis, but it cannot tell which is/are the other sprites involved. So let's suppose you want to check if OB1 and OB2 collide:
http://www.tilengine.org/doc/md_sprites.html#autotoc_md99 vs Foreground Tiles Doing sprite vs tiles means examining the tiles that overlap with the area of a sprite A common optimization is to check only the tiles that overlap with the edges facing the motion vector of the sprite. For example:
Here's the documentation for querying tile data: http://www.tilengine.org/doc/md_layers.html#autotoc_md47 For a working example, you can check source code of my sister project Python Platformer. It uses the python binding, but you'll get the idea. Sprite vs sprite and vs tile layer are demosntrated: https://github.com/megamarc/TilenginePythonPlatformer Regards, RE: Check sprite collision with other sprite - Midnight Syntax - 05-05-2021 Okay great, thanks so much! RE: Check sprite collision with other sprite - namarang - 08-11-2021 Hi You have to climb over falling blocks of the sky by moving them around around to reach your home cloud level. So far it seems its more likely the game is going to be about how falling blocks are gonna drown in each other taking you with you |