简体   繁体   中英

collision detection, in libgdx

I am new to the world of libgdx and the world of game programming in general. I want to create a game, but not any game. I have created some basic game like breaks , and pong . But I still cant go any further, I google for good articles, but I always have problems with collision, especially between entities! I want to create a game with slopes like sonic .

Why not use Box2D (libGDX extension) ? It's perfect for platformers.

Do you know how to create rectangles. I assume that you know about rectangles. if you want to check collision of two rectangles you can do as follows:

Rectangle a = new Rectangle(), b = new Rectangle();

in constructor set rectangles

a.setRectangle(yourX, yourY, yourWidth, yourHeight);
b.setRectangle(yourX, yourY, yourWidth, yourHeight);

in render check collision like this:

if(a.overlaps(b))
{
  //do your work
}

您可以使用LibGdx在SuperJumper Project中提供的OverlapTester类

Create Your bounds using rectangle class in Libgdx and test them using Intersector class.

This class has many function to test overlapping of rectangles, circles etc..

I recommend you to use box2d if you know the basics. if you know how to use a rectangle, sprite batch, camera etc. Then you should proceed to Box2d if you don't just take some good tutorial and try to make the application without any extension.this will make your concept clear and you will easily able to grasp the logic behind the game.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM