I was on a roll last night, when I came across the issue of the ButtonSprite. I could have sworn I've done this before - it seems so simple - but using the code that AndEngineExamples provides doesn't really make sense and comes up with errors (for instance - why does a vague "run()" method create the response to every single touch event?).
So I did something that seemed to make sense.
private void loadScenes()
{
mainScene = new Scene();
menu = new Sprite(0, 0, menuTextureRegion, mEngine.getVertexBufferObjectManager()){
@Override
protected void preDraw(GLState pGLState, Camera pCamera)
{
super.preDraw(pGLState, pCamera);
pGLState.enableDither();
}
};
newgamebutton = new ButtonSprite(25, 200, newgameTextureRegion, mEngine.getVertexBufferObjectManager());
multiplayerbutton = new ButtonSprite(25, 310, multiplayerTextureRegion, mEngine.getVertexBufferObjectManager());
menu.setScale(1.65f);
menu.setPosition((CAMERA_WIDTH - menu.getWidth()) * 0.5f, (CAMERA_HEIGHT - menu.getHeight()) * 0.5f);
mainScene.attachChild(menu);
mainScene.attachChild(newgamebutton);
mainScene.attachChild(multiplayerbutton);
mainScene.registerTouchArea(multiplayerbutton);
mainScene.setTouchAreaBindingOnActionDownEnabled(true);
multiplayerbutton.onAreaTouched(mButtonTouched, multiplayerbutton.getWidth(), multiplayerbutton.getHeight());
if(mButtonTouched.isActionDown()) {
mainScene.detachChild(menu);
mainScene.detachChild(multiplayerbutton);
}
}
It seems to make good sense. When the "multiplayer button" is pressed, it gives you the mButtonTouched, and when that's pressed down... it detaches the menu and multiplayer button. This is obviously just me testing things, and not part of any actual project because I'm just learning, but I get a null pointer exception and the app right closes before displaying the "Menu Scene", which obviously normally works. Also, on various sites it says that I should put "public boolean" before multiplayerbutton, but Eclipse won't have that.
I'm sure you guys have already figured this out, but I'm suuuuuuper new to AndEngine. Thanks for any help, guys!