0

I wanna move a physics body(Duck) to accurate direction when user swipe the body. I can detect the scene swipe event. But how to connect with my body, when swiped.

My code: In my game Scene Class >>

    // called in scene constructor


    private void addDuck(final float pX, final float pY) {

            duck = new Duck(pX, pY, resourcesManager.mDuckTextureRegion,
                    vertexBufferObjectManager) {
           @Override
            public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
                    float pTouchAreaLocalX, float pTouchAreaLocalY) {


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

                Log.e("onAreaTouched", "Inside Duck");

                return true;
            }

            };

            body = PhysicsFactory.createCircleBody(this.mPhysicsWorld, duck,
                    BodyType.DynamicBody, objectFixtureDef);
            duck.setPhysicsWorld(mPhysicsWorld, body);
            registerTouchArea(duck);
            getChildByIndex(SECOND_LAYER).attachChild(duck);
            duckList.add(duck);
            body.setGravityScale(0);
        }

Now my object don't move to any direction. I got the IOS code implementation here. can some body help to do this in ANDROID.

Shihab Uddin
  • 6,699
  • 2
  • 59
  • 74

1 Answers1

1
   @Override
                public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
                        float pTouchAreaLocalX, float pTouchAreaLocalY) {
                                        if (pSceneTouchEvent.isActionMove()) {
                      this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2,
                            pSceneTouchEvent.getY() - this.getHeight() / 2);
                        return true;
                    }
                    return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX,
                            pTouchAreaLocalY);
                }
            };
Izu
  • 235
  • 1
  • 5