0
votes

I have 2 sprites, I would like to move both of them, when I touched sprite A and moved it, sprite B will be moved also without touching sprite B at the same time. thanks for the help

here is the code

I have 2 sprites, I would like to move both of them, when I touched sprite A and moved it, sprite B will be moved also without touching sprite B at the same time. thanks for the help

here is the code

center = new AnimatedSprite(0, 0, resourcesManager.interact, vbom) {

@Override public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,final float pTouchAreaLocalX, final float pTouchAreaLocalY)

{

            //SPrite A
            this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2,
                    pSceneTouchEvent.getY() - this.getHeight() / 2);
            //Sprite B
                return true;
        }
    };
2

2 Answers

0
votes

If you can post some code it would help in creating a more helpful answer.

In essence, when you handle the touch event and apply the movement to sprite A all you need to do is also apply the movement to sprite B.

If you post your code I will be able to edit and add an example.

0
votes

You can change position of sprite B at the same moment with sprite A, inside spriteA's onAreaTouched method:

public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,final float    pTouchAreaLocalX, final float pTouchAreaLocalY)

{

        //SPrite A
        this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2,
                pSceneTouchEvent.getY() - this.getHeight() / 2);
        spriteB.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2,
                pSceneTouchEvent.getY() - this.getHeight() / 2);

};