I have drawn a line on sprite(Bow) and i want to stretch it using onTouch by fingers. I have added Physics body but not getting how to stretch the line. Its a bow and arrow demo. Please see attached image Bow sprite with line drawn

protected Scene onCreateScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());
        mScene = new Scene();
        mScene.setBackground(new Background(0.3f, 0.8f, 0.9f));
        float centerX = CAMERA_WIDTH/2;
        float centerY = CAMERA_HEIGHT/2;

        Sprite sprite = new Sprite(centerX,centerY,this.regionBow, this.getVertexBufferObjectManager());

        PhysicsWorld physicsWorld = new PhysicsWorld(new Vector2(0, 300), false);
        Line line = new Line(99, 10, 99, 240, 4, getVertexBufferObjectManager());

        FixtureDef lineFixtureDef = PhysicsFactory.createFixtureDef(1, 4f, 0.5f);
        Body body = PhysicsFactory.createLineBody(physicsWorld, line, lineFixtureDef);

        PhysicsConnector physicsConnector = new PhysicsConnector(sprite, body, true, true);

        mScene.setOnAreaTouchListener(new IOnAreaTouchListener() {
            public boolean onAreaTouched(TouchEvent pSceneTouchEvent, ITouchArea pTouchArea, float pTouchAreaLocalX, float pTouchAreaLocalY) {
                return false;

        return this.mScene;

Maybe you can not use physics. Something like this;

float[] bowLeftUpCornerPos =... // add Bow left-up corner positions.
float[] bowLeftDownCornerPos=... // add Bow left-down corner positions.
float[] bowLeftCenterPos=... // add Bow left center positions.

Line lineUp = new Line(bowLeftCenterPos[0], bowLeftCenterPos[1],
bowLeftUpCornerPos[0] , bowLeftUpCornerPos[1], 4, getVertexBufferObjectManager());

Line lineDown = new Line(bowLeftCenterPos[0], bowLeftCenterPos[1],
bowLeftDownCornerPos[0], bowLeftDownCornerPos[1], 4, getVertexBufferObjectManager());

public boolean onAreaTouched(TouchEvent pSceneTouchEvent,     ITouchArea pTouchArea, float pTouchAreaLocalX, float pTouchAreaLocalY) {

    float pX = pSceneTouchEvent.getX();
    float pY = pSceneTouchEvent.getY();

    if (pSceneTouchEvent.isActionDown() || pSceneTouchEvent.isActionMove()) {

    if (pSceneTouchEvent.isActionUp()) {
       lineUp.setPosition(bowLeftCenterPos[0], bowLeftCenterPos[1],bowLeftUpCornerPos[0],bowLeftUpCornerPos[1]);
       lineDown.setPosition(bowLeftCenterPos[0], bowLeftCenterPos[1],bowLeftDownCornerPos[0],bowLeftUpCornerPos[1]);

return false;

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.