Reputation: 129
I'm pretty new to AndEngine, and I have a question. I want to make it so if I touch on the sprite or the body then something will remove that sprite or body for me.
Upvotes: 2
Views: 8567
Reputation: 67296
Try this,
Implement your class with IOnSceneTouchListener
scene.setOnSceneTouchListener(this);
And you can write your stuff in the below implemented method.
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent event) {
// your stuff here
return false;
}
Upvotes: 4
Reputation: 7976
final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
yourSceneClass.this.runOnUpdateThread(new Runnable() {
@Override
public void run() {
/* Now it is save to remove the entity! */
pScene.detachChild(yourSceneClass.this.face);
}
});
}
};
pScene.attachChild(face);
pScene.registerTouchArea(face);
pScene.setTouchAreaBindingEnabled(true);
It should be something in this general direction.
Has a lot of examples of the person who made andengine, it's a good idea to atleast look at all of them once.
Upvotes: 1
Reputation: 2494
Use
final Sprite mySprite = newSprite(100, 220, this.mySpriteTextureRegion) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
// here you can use the code
}
};
have to register with screen for touch area as
scene.registerTouchArea(mySprite);
scene.setTouchAreaBindingEnabled(true);
May be it helpful to you..
Upvotes: 4