我已经开始学习 andegine 并且我对 box2d 扩展有一些问题。我有这个代码,它给了我黑屏。当我删除制作 PhysicsWorld 时,它可以工作。
package com.cupofcoffee.heartjump;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.util.FPSCounter;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.color.Color;
import android.hardware.SensorManager;
import com.badlogic.gdx.math.Vector2;
public class MainActivity extends SimpleBaseGameActivity {
static final int CAMERA_WIDTH = 800;
static final int CAMERA_HEIGHT = 480;
Camera camera;
Scene gameScene;
Heart heart;
PhysicsWorld physicsWorld;
@Override
public EngineOptions onCreateEngineOptions() {
this.camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
EngineOptions engineOptions = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(),
camera);
return engineOptions;
}
@Override
protected void onCreateResources() {
}
@Override
protected Scene onCreateScene() {
mEngine.registerUpdateHandler(new FPSCounter());
gameScene = new Scene();
gameScene.setBackground(new Background(1, 1, 1));
physicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
// heart = new Heart(500, 100, this, getVertexBufferObjectManager(), physicsWorld);
// gameScene.registerUpdateHandler(physicsWorld);
// gameScene.attachChild(heart.sprite);
Rectangle r = new Rectangle(100, 100, 100, 100,
getVertexBufferObjectManager());
r.setColor(new Color(50, 50, 50));
gameScene.attachChild(r);
return gameScene;
}
}
那有什么问题?我真的找不到解决办法。