1

我已经开始学习 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;
    }

}

那有什么问题?我真的找不到解决办法。

4

2 回答 2

0

您可以设置颜色背景。

gameScene.setBackground(new ColorBackground(1, 1, 1));

或者如果设置任何图像然后

gameScene.setBackground(new SpriteBackground(yourSprite));
于 2013-04-20T10:23:46.123 回答
0

我认为这是无效的:
new Color(50, 50, 50)
每个参数的有效范围是 0-1,而不是 0-255

另外,尝试:
gameScene.setBackground(new Background(Color.RED));

于 2013-04-19T19:58:09.670 回答