0
我下面教程在https://jimmaru.wordpress.com/2012/05/19/jimvaders-my-own-invaders-clone-thingie-tutorial/AndEngine:只是一個黑色的背景,字體不顯示
我有下面顯示文本從一側滾動到另一側的代碼。現在我得到的只是一個黑色的矩形,填滿了大部分屏幕,沒有文字出現,沒有錯誤。 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));
}
}
是否可以更改字體顏色? – KJW
是的。最常用的方法是使用樣式,但是這裏有一個TextView代碼:http://stackoverflow.com/questions/4602902/how-to-set-text-color-of-textview-by-coding – Zagrev