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\$
1
  • \$\begingroup\$ On a unrelated note: If your setPosition is not different in your derived class then calling super is pointless. Harmless, but pointless. \$\endgroup\$ Commented Jun 25, 2013 at 7:45

2 Answers 2

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\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.