Reputation: 265
I'm developing a game via Andengine and I'm stuck somewhere! The problem is: It is adding a sprite where I touch on scene(touchX, touchY) and one sprite is adding at (touchX+100, touchY). These two sprites always have 100px between eact other on x axis. Untill now, I touch one time and added two sprites on scene. Then, when I wanna move one of them(let's say first one), the second one has to move too to keep distance(100px) betwwen them. My codes are below, these codes added corretly but only one of them is moving that's why the other can't keep the distance constantly. How can I do that correctly?
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
if(pSceneTouchEvent.getAction() == MotionEvent.ACTION_DOWN)
{
touchX = pSceneTouchEvent.getX();
touchY = pSceneTouchEvent.getY();
}
if(pSceneTouchEvent.getAction() == MotionEvent.ACTION_UP)
{
}
if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_MOVE){
AnimatedSprite circleBoxE1 = new AnimatedSprite(touchX, touchY, resourcesManager.circleBoxRegion, vbom){
@Override
public boolean onAreaTouched(TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
this.setPosition(pTouchEvent.getX(), pTouchEvent.getY());
return true;
}
};
registerTouchArea(circleBoxE1);
attachChild(circleBoxE1);
setTouchAreaBindingOnActionDownEnabled(true);
AnimatedSprite circleBoxE2 = new AnimatedSprite(touchX, 450 - touchY, resourcesManager.circleBoxRegion, vbom){
@Override
public boolean onAreaTouched(TouchEvent pTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
this.setPosition(pTouchEvent.getX() + 100, pTouchEvent.getY());
return true;
}
};
registerTouchArea(circleBoxE2);
attachChild(circleBoxE2);
setTouchAreaBindingOnActionDownEnabled(true);
}
Upvotes: 0
Views: 75
Reputation: 1156
If You want to update two positions on scene touch follow as below:
Ex: sprite1.setPosition(touchX, touchY); sprite2.setPosition(sprite1.getX()+100, touchY);
if you want to update on sprite1 touch
Ex: this.setPositon(touchX, touchY); sprite2.setPosition(this.getX()+100, touchY);
you can update one sprite when another is updating by using updateHandlers:
Upvotes: 1