我正在使用AndEngine进行游戏开发,我的问题是我不知道我应该如何将多边形体设置为精灵.
我尝试过这里提到的代码http://www.andengine.org/forums/gles1/complex-collision-surface-t5593.html#p24822但没有成功.
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;
解决方法:
我终于使用PhysicsEditor解决了这个问题,它的加载器:http://www.codeandweb.com/physicseditor