私はAndroid開発の初心者であり、AndEngineを使用してゲームを開発し、ナビゲーションにSherlockActionBarを使用したいと考えています。問題は、AndEngineではSimpleBaseGameActivityを拡張する必要があり、SherlockActionBarではSherlockActivityを拡張する必要があることです。ネストされたクラスアプローチを使用しようとしていますが、OnCreate中にAndEngineを初期化する方法がわかりません。どんな助けでも大歓迎です。
--編集--ActionBarSherlockの例で静的添付ファイルのデモをいじくり回しましたが、既存のAndEngineデモコードにはOnCreateメソッドがないため、これを機能させる方法を理解できません。
public class WABActivity extends SimpleBaseGameActivity implements IOnMenuItemClickListener, OnCreateOptionsMenuListener {
ActionBarSherlock mSherlock = ActionBarSherlock.wrap(this);
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
protected static final int MENU_RESET = 0;
protected static final int MENU_QUIT = MENU_RESET + 1;
private Camera mCamera;
protected Scene mMainScene;
private BitmapTextureAtlas mBitmapTextureAtlas;
private ITextureRegion mFaceTextureRegion;
private Font mFont;
protected MenuScene mMenuScene;
@Override
public EngineOptions onCreateEngineOptions() {
this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera);
}
@Override
public void onCreateResources() {
FontFactory.setAssetBasePath("font/");
final ITexture fontTexture = new BitmapTextureAtlas(this.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
this.mFont = FontFactory.createFromAsset(this.getFontManager(), fontTexture, this.getAssets(), "Plok.ttf", 48, true, android.graphics.Color.WHITE);
this.mFont.load();
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 64, 64, TextureOptions.BILINEAR);
this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "face_box_menu.png", 0, 0);
this.mBitmapTextureAtlas.load();
}
@Override
public Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
this.mMenuScene = this.createMenuScene();
/* Just a simple scene with an animated face flying around. */
this.mMainScene = new Scene();
this.mMainScene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
final Sprite face = new Sprite(0, 0, this.mFaceTextureRegion, this.getVertexBufferObjectManager());
face.registerEntityModifier(new MoveModifier(30, 0, CAMERA_WIDTH - face.getWidth(), 0, CAMERA_HEIGHT - face.getHeight()));
this.mMainScene.attachChild(face);
setTheme(R.style.Theme_Sherlock); //<--Not sure if this goes here
mSherlock.setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW); //<--Not sure if this goes here
mSherlock.setContentView(???); //<--How do I set ContentView? Do I need to set contentview?
return this.mMainScene;
}
@Override
public boolean onKeyDown(final int pKeyCode, final KeyEvent pEvent) {
if(pKeyCode == KeyEvent.KEYCODE_MENU && pEvent.getAction() == KeyEvent.ACTION_DOWN) {
if(this.mMainScene.hasChildScene()) {
/* Remove the menu and reset it. */
this.mMenuScene.back();
} else {
/* Attach the menu. */
this.mMainScene.setChildScene(this.mMenuScene, false, true, true);
}
return true;
} else {
return super.onKeyDown(pKeyCode, pEvent);
}
}
@Override
public boolean onMenuItemClicked(final MenuScene pMenuScene, final IMenuItem pMenuItem, final float pMenuItemLocalX, final float pMenuItemLocalY) {
switch(pMenuItem.getID()) {
case MENU_RESET:
/* Restart the animation. */
this.mMainScene.reset();
/* Remove the menu and reset it. */
this.mMainScene.clearChildScene();
this.mMenuScene.reset();
return true;
case MENU_QUIT:
/* End Activity. */
this.finish();
return true;
default:
return false;
}
}
protected MenuScene createMenuScene() {
final MenuScene menuScene = new MenuScene(this.mCamera);
final IMenuItem resetMenuItem = new ColorMenuItemDecorator(new TextMenuItem(MENU_RESET, this.mFont, "RESET", this.getVertexBufferObjectManager()), new Color(1,0,0), new Color(0,0,0));
resetMenuItem.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
menuScene.addMenuItem(resetMenuItem);
final IMenuItem quitMenuItem = new ColorMenuItemDecorator(new TextMenuItem(MENU_QUIT, this.mFont, "QUIT", this.getVertexBufferObjectManager()), new Color(1,0,0), new Color(0,0,0));
quitMenuItem.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
menuScene.addMenuItem(quitMenuItem);
menuScene.buildAnimations();
menuScene.setBackgroundEnabled(false);
menuScene.setOnMenuItemClickListener(this);
return menuScene;
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
return mSherlock.dispatchCreateOptionsMenu(menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
sub = menu.addSubMenu("Options");
sub.add(0, 1, 0, "Settings");
sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true;
}
@Override //<-- Giving Error: must override or implement a supertype method
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home || item.getItemId() == 0) {
return false;
}
if(item.getItemId()==1){
//SETTINGS SCREEN//
sub.removeItem(1);
sub.removeItem(2);
sub.removeItem(3);
sub.removeItem(4);
sub.removeItem(5);
sub.add(0, 5, 0, "Home");
sub.add(0, 2, 0, "High Scores");
sub.add(0, 3, 0, "Help");
sub.add(0, 4, 0, "About");
//mMode = startActionMode(new AnActionModeOfEpicProportions());
}
}
}