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

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...