除了libandenginephysicsbox2dextension.so之外,在andengine中集成box2d需要附加的jar

时间:2012-03-30 09:31:44

标签: android box2d andengine

我使用下面的代码,只是为了绘制一个精灵并设置屏幕的边界。然后给那个精灵创建一个主体并向主体添加一个夹具定义。然后我使用了物理连接器来组合精灵但是我无法看到身体在移动。我得到的结果只是屏幕上的精灵,但身体和它的属性没有集成到精灵。任何人都可以通过我写的代码并纠正我,我遵循了发动机实例中的所有规则,

public class BallGameWithAndEngineActivity extends BaseGameActivity 
{
public static final int CAMERA_WIDTH = 800;
public static final int CAMERA_HEIGHT = 480;
private TextureRegion mBoxFaceTextureRegion;
private BitmapTexture mBitmapTexture;
private Body mGroundBody;
private PhysicsWorld mPhysicsWorld;
private Scene mScene;
private ZoomCamera camera;
public static float maxZoom = 4;
public static float minZoom = 0.4f;
public static float minX = 200;
public static float maxX = 200;
public static float minY = 200;
public static float maxY = 200;
@Override
public void onLoadComplete() 
{
}
@Override
public Engine onLoadEngine() {
this.camera = new ZoomCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);        
camera.setBounds(0 - minX, CAMERA_WIDTH + minX, 0 - minY, CAMERA_HEIGHT + maxY); 
this.camera.setBoundsEnabled(true);
final EngineOptions engineOptions = new EngineOptions(true,
ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(
CAMERA_WIDTH, CAMERA_HEIGHT), camera);
engineOptions.getTouchOptions().setRunOnUpdateThread(true);
Engine engine = new Engine(engineOptions);
try 
{
if (MultiTouch.isSupported(this)) {
engine.setTouchController(new MultiTouchController());
} 
else 
{
Toast.makeText(this,"Sorry your device does NOT support MultiTouch!\n\n(No  
PinchZoom is possible!)",Toast.LENGTH_LONG).show();
}
} 
catch (final MultiTouchException e) {
Toast.makeText(this,"Sorry your Android Version does NOT support MultiTouch!\n\n(No 
PinchZoom is possible!)",Toast.LENGTH_LONG).show();
}
return engine;
}
@Override
public void onLoadResources() {
BitmapTextureRegionFactory.setAssetBasePath("gfx/");
this.mBitmapTexture = new BitmapTexture(1024, 256,
TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.mBoxFaceTextureRegion = BitmapTextureRegionFactory
.createFromAsset(this.mBitmapTexture, this, "face_box.png", 0,0);
this.mEngine.getTextureManager().loadTexture(this.mBitmapTexture);
this.mPhysicsWorld = new PhysicsWorld(new Vector2(0,
SensorManager.GRAVITY_EARTH), false);
}
@Override
public Scene onLoadScene() 
{
final Sprite face;
final Body body;
this.mScene = new Scene();
this.mScene.setBackground(new ColorBackground(0, 0, 0));
this.mGroundBody = this.mPhysicsWorld.createBody(new BodyDef());
FixtureDef FIXTURE_DEF = PhysicsFactory
.createFixtureDef(1, 0.3f, 0.7f);
face = new Sprite(100, 100, this.mBoxFaceTextureRegion);
body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face,
BodyType.DynamicBody, FIXTURE_DEF);
face.setUserData(body);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face,
body, true, true));
final Shape ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH,
2);
final Shape roof = new Rectangle(0, 0, CAMERA_WIDTH, 2);
final Shape left = new Rectangle(0, 0, 2, CAMERA_HEIGHT);
final Shape right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT);
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0,
0.5f);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, left,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, right,
BodyType.StaticBody, wallFixtureDef);
this.mScene.attachChild(ground);
this.mScene.attachChild(roof);
this.mScene.attachChild(left);
this.mScene.attachChild(right);
this.mScene.attachChild(face);
final PhysicsHandler physicsHandler = new PhysicsHandler(face);
face.registerUpdateHandler(physicsHandler);
this.mScene.registerTouchArea(face);
return this.mScene;
}
}

0 个答案:

没有答案