0
\$\begingroup\$

I want to set anchor point for the sprite like cocos2d has done for their implementation. I do not found any thing like that in andengine so please provide guidance on that. I want to move the sprite on touch so I use following code but that does not work for me.

super.setPosition(pX - this.getWidthScaled() / 2,
            pY - this.getHeightScaled() / 2);

Because I touch on the corner of the image but automatically it comes at center of the image because of above code. I want to remain the touch at desire position and drag it. For me the anchor point became useful. But I don't found anything in andengine.

\$\endgroup\$
  • \$\begingroup\$ On a unrelated note: If your setPosition is not different in your derived class then calling super is pointless. Harmless, but pointless. \$\endgroup\$ – Sidar Jun 25 '13 at 7:45
2
\$\begingroup\$

This is pretty basic, you need to remember the distance from the center when you first touch the Sprite and then take this into account when moving it around.

\$\endgroup\$
0
\$\begingroup\$

Not sure if this is what you want, because I don't know cocos2d. Entity in AndEngine has method:

@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
    return false;
}

The pTouchAreaLocalX and pTouchAreaLocalY will give you relative position of touch inside the entity and pSceneTouchEvent then contains the absolute position on screen. You can use the local coordinates to correct the position.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.