In my app i need to add multiple sprite and add event to them. What i am doing now is using individual event listener for each and every sprite which is a kind of mess.
buttonS[0] = new Sprite(x_pos += 0, y_pos, orangeNumImage[0], this.getVertexBufferObjectManager()) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
if(pSceneTouchEvent.isActionDown()) {
//Perform Some task
}
return true;
} else {
//Perform Some task
return false;
}
}
};
buttonS[1] = new Sprite(x_pos += 115, y_pos, orangeNumImage[1], this.getVertexBufferObjectManager()) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
if(pSceneTouchEvent.isActionDown()) {
//Perform Some task
}
return true;
} else {
return false;
}
}
};
I was searching to handle this event with just one event listener and make the code shorter.
In normal android (without andengine) we could use something like this (by using android:onclick to areaTouched in button):-
public void areaTouched(View view) {
Button nextclick = (Button) findViewById(R.id.button_nextClick);
Button b = (Button)view;
int check = Integer.parseInt(b.getText().toString());
if (check == i){
........
}
}