Move an Actor (image) in Screen2d By 2 fingers (pinch)

Anything libgdx related goes here!

Move an Actor (image) in Screen2d By 2 fingers (pinch)

Postby MMM1412 » Wed Jun 13, 2018 9:18 am

Hi guys, I am trying create one photography App by libgdx And I want users can move their image (an actor in screen2d) by 2 fingers. I tried many ways but Its dont work as i want .

here is my code:
Code: Select all
nhomanh.addListener(new ActorGestureListener() {
            @Override
            public void touchDown(InputEvent event, float x, float y, int pointer, int button) {

                scalecenter = myimage.getScaleX();

                super.touchDown(event, x, y, pointer, button);
            }

            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
         
                super.touchUp(event, x, y, pointer, button);
            }

            @Override
            public void pan(InputEvent event, float x, float y, float deltaX, float deltaY) {
           
                super.pan(event, x, y, deltaX, deltaY);
            }


            @Override
            public void pinch(InputEvent event, Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
         

                float icx = (initialPointer1.x + initialPointer2.x) / 2;
                float icy = (initialPointer1.y + initialPointer2.y) / 2;

                float tcx = (pointer1.x + pointer2.x) / 2;
                float tcy = (pointer1.y + pointer2.y) / 2;


        myimage.setPosition(
            (tcx-icx)*myimage.getScaleX()+myimage.getX(),
            (tcy-icy)*myimage.getScaleY()+myimage.getY()
    );

    Controlimage();


Anybody have same problem. We could discuss to find solotion. Thanks for any idea !!
MMM1412
 
Posts: 118
Joined: Mon Sep 14, 2015 10:48 am

Return to Libgdx

Who is online

Users browsing this forum: Google [Bot] and 1 guest