How to drag an andEngine sprite anywhere on the phone screen?

I have written this code in onAreaTouched function of IOnAreaTouchListener interface which is implemented in my activity, but its not working:

public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
      ITouchArea pTouchArea, float pTouchAreaLocalX,
      float pTouchAreaLocalY) {
    // TODO Auto-generated method stub

    Log.v(TAG,"Sprite Touched ##########");

    secondSprite = new 
            playerTextureRegion, this.getVertexBufferObjectManager()){
        public boolean onAreaTouched(final TouchEvent pSceneTouchEvent,
                                     final float pTouchAreaLocalX,
                                     final float pTouchAreaLocalY) {
            secondSprite.setPosition(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
            System.out.println(String.format("spriteB %fx%f", pSceneTouchEvent.getX(), 
            return true;
    return true;
  • \$\begingroup\$ What is the behaviour you're currently getting? \$\endgroup\$ – Alexandre Vaillancourt Jun 27 '15 at 11:57
  • \$\begingroup\$ You don't add secondSprite to your scene by the way. \$\endgroup\$ – dwursteisen Jul 30 '15 at 14:28

Your Answer

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

Browse other questions tagged or ask your own question.