我正在关注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));
}
}