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;
source share