I have code like this:
mButton = new ButtonSprite(400 , 400, myTiledTextureRegion.getTextureRegion(0), myTiledTextureRegion.getTextureRegion(1),
activity.getVertexBufferObjectManager(), new OnClickListener() {
@Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX,
float pTouchAreaLocalY) {
Toast.makeText(MenuScene.this.activity, "Clicked", Toast.LENGTH_LONG).show();
}
});
this.attachChild(mButton);
My problem is that when I Click on my button i don’ t get toast message (log the same) and aslo sprite doesn’t change for myTiledTextureRegion.getTextureRegion(1). I don’ t know why?
I can click on button, but there is no reaction. I tried use AnimatedSprite to test resources and it display animation correctly. Why my ButtonSprite OnClickListener and sprite change there don’ work ?
Way i load resources:
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
mBitmapTextureAtlas = new BuildableBitmapTextureAtlas(activity.getTextureManager(), 512, 256, TextureOptions.NEAREST);
myTiledTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(mBitmapTextureAtlas, activity, "btn.png", 1, 3);
try {
mBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 0, 1));
mBitmapTextureAtlas.load();
} catch (TextureAtlasBuilderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I do everything on my Scene class, because i have only one activity (and many scenes). Thanks for help.
see if this is the issue … before you attach the button with
this.attachChild(mButton);be sure and also register the touch area withthis.registerTouchArea(mButton);