微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 和引擎多边形

我正在使用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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐