And the engine polygons

I use AndEngine to develop a game, and my problem is that I donโ€™t know how exactly I should set the body of the polygon for the sprite.

I tried the code mentioned here http://www.andengine.org/forums/gles1/complex-collision-surface-t5593.html#p24822 , but failed.

Is there any other way how to make it work? I also attach my code:

if (type.equals(ObjectType.STAIRS)) { final BodyDef bodyDef = new BodyDef(); bodyDef.type = type.bodyType; bodyDef.position.x=5; bodyDef.position.y=5; final Body mBody = body; PolygonShape pol1 = new PolygonShape(); Vector2[] vertices = {//rectangular new Vector2(0, -sprite.getHeight() * 0.5f),//top right new Vector2(-sprite.getWidth() * 0.5f,//top left -sprite.getHeight() * 0.5f), new Vector2(-sprite.getWidth() * 0.5f,//bottom left sprite.getHeight() * 0.5f), new Vector2(0,//bottom right sprite.getHeight() * 0.5f) }; pol1.set(vertices); fixtureDef.shape = pol1; mBody.createFixture(fixtureDef); pol1.dispose(); final PolygonShape pol2 = new PolygonShape(); Vector2[] vertices2 = {//triangular new Vector2(0, -sprite.getHeight() * 0.5f),//top new Vector2(0, sprite.getHeight() * 0.5f),//left new Vector2(sprite.getWidth() * 0.5f, sprite.getHeight() * 0.5f),//right }; pol1.set(vertices2); fixtureDef.shape = pol2; mBody.createFixture(fixtureDef); pol2.dispose(); body=mBody; 
+4
source share
2 answers

I finally solved this problem using PhysicsEditor and the loader: http://www.codeandweb.com/physicseditor

+1
source

it looks like you did not use the width factor and the constant ratio of pixels to counter to make it in meters.

you need to use a physical connector to register the body for the sprite, which I think ...

0
source

Source: https://habr.com/ru/post/1396096/


All Articles