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));
}
}