AndEngine:只是黑色背景,字体没有显示

时间:2012-10-12 22:32:05

标签: java android andengine

我正在关注https://jimmaru.wordpress.com/2012/05/19/jimvaders-my-own-invaders-clone-thingie-tutorial/

上的教程

我下面的代码应该显示从一边到另一边滚动的文本。现在我得到的只是一个填满屏幕大部分的黑色矩形,没有文字出现,没有错误。 FPSManager显示60fps。我在res / values / strings.xml设置中有title_1和title_2。

MainActivity.java

package com.example.hh;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.util.FPSLogger;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.Typeface;
import android.view.Menu;

public class MainActivity extends SimpleBaseGameActivity {

    static final int cWidth = 800;
    static final int cHeight = 480;

    public Font mFont;
    public Camera mCamera;

    public Scene mCurrentScene;
    public static MainActivity instance;

    @Override
    public EngineOptions onCreateEngineOptions() {
        // TODO Auto-generated method stub

        instance = this;
        mCamera = new Camera(0,0, cWidth, cHeight);

        return new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, 
                new RatioResolutionPolicy(cWidth,cHeight),mCamera);

    }

    @Override
    protected void onCreateResources() {
        // TODO Auto-generated method stub
        mFont = FontFactory.create(this.getFontManager(), this.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT,Typeface.BOLD), 32);
        mFont.load();
    }

    @Override
    protected Scene onCreateScene() {
        // TODO Auto-generated method stub
        mEngine.registerUpdateHandler(new FPSLogger());
        mCurrentScene = new SplashScene();
        return mCurrentScene;
//      mEngine.registerUpdateHandler(new FPSLogger());
//      mCurrentScene = new Scene();
//      mCurrentScene.setBackground(new Background(0.09804f,0.7274f,0.8f));
//      return mCurrentScene;
    }

    public static MainActivity getSharedInstance(){
        return instance;
    }

    public void setCurrentScene(Scene scene){
        mCurrentScene = scene;
        getEngine().setScene(mCurrentScene);
    }
}

SplashScene.java

package com.example.hh;

import org.andengine.entity.modifier.MoveXModifier;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.text.Text;

public class SplashScene extends Scene {

    MainActivity activity;

    public void SplashScene(){
        setBackground(new Background(0.09804f, 0.6274f, 0));

        activity =  MainActivity.getSharedInstance();

        Text title1 = new Text(0,0, activity.mFont,activity.getString(R.string.title_1),activity.getVertexBufferObjectManager());
        Text title2 = new Text(0,0, activity.mFont, activity.getString(R.string.title_2), activity.getVertexBufferObjectManager());

        title1.setPosition(-title1.getWidth(), activity.mCamera.getHeight() / 2);
        title2.setPosition(activity.mCamera.getWidth(), activity.mCamera.getHeight() /2);

        attachChild(title1);
        attachChild(title2);

        title1.registerEntityModifier(new MoveXModifier(1,title1.getX(),activity.mCamera.getWidth()/2 - title1.getWidth()));
        title2.registerEntityModifier(new MoveXModifier(1,title2.getX(), activity.mCamera.getWidth() /2));

    }

}

1 个答案:

答案 0 :(得分:1)

将前景设置为白色(或非黑色)的行在哪里?