box2d + scene2d strange behavior

Anything libgdx related goes here!

Re: box2d + scene2d strange behavior

Postby shatterblast » Thu Aug 29, 2019 6:02 pm

So you can see the Button animate when pressed?
shatterblast
 
Posts: 414
Joined: Sun Jul 06, 2014 1:14 pm

Re: box2d + scene2d strange behavior

Postby TruePlayer » Thu Aug 29, 2019 6:15 pm

I don’t see the main texture of the button, but I see additional textures when I click
Image

P,S,
it’s strange that the size of the advertisement is larger than 320) my camera is 320x480
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: box2d + scene2d strange behavior

Postby shatterblast » Thu Aug 29, 2019 6:21 pm

I added this to a previous posting, but just in case, I add it here:
If you do have a problem, then the issue is probably with your Camera, and if found true, then I think the ASPECT_RATIO variable in your GameView class might make your device input come inaccurately. I suggest temporarily removing the ASPECT_RATIO variable from your Camera code to see what happens in that case.
shatterblast
 
Posts: 414
Joined: Sun Jul 06, 2014 1:14 pm

Re: box2d + scene2d strange behavior

Postby TruePlayer » Thu Aug 29, 2019 6:25 pm

Code: Select all
CAMERA_WIDTH = game.getWeight();
        CAMERA_HEIGHT = game.getHeight();
        ASPECT_RATIO = gsm.getWeight() / gsm.getHeight();
        viewPort = new FillViewport(CAMERA_WIDTH,CAMERA_HEIGHT);
        this.camera.setToOrtho(true, CAMERA_WIDTH, CAMERA_HEIGHT);
        this.camera.position.set(new Vector3(CAMERA_WIDTH / 2f, CAMERA_HEIGHT / 2f, 0));


no result
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: box2d + scene2d strange behavior

Postby shatterblast » Thu Aug 29, 2019 7:00 pm

I think your Viewport is not registering the Camera, and so, it separately made its own. You might try this:

Code: Select all
//Notice that the order is swapped.
this.camera.setToOrtho(true, CAMERA_WIDTH, CAMERA_HEIGHT);
viewPort = new FillViewport(CAMERA_WIDTH, CAMERA_HEIGHT, this.camera);
shatterblast
 
Posts: 414
Joined: Sun Jul 06, 2014 1:14 pm

Re: box2d + scene2d strange behavior

Postby TruePlayer » Thu Aug 29, 2019 7:09 pm

your code completely reflected the whole world but did not solve the problem
Image
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: box2d + scene2d strange behavior

Postby evilentity » Thu Aug 29, 2019 7:41 pm

Instead of typing stuff in randomly, try figuring out what stuff does.
Dont touch the camera, viewport is there to make it work.
Size of the world is something you decide, not whatever the window is right now.
Looking for a freelancer? PM me!
Check out libgdx discord server!
evilentity
 
Posts: 4854
Joined: Wed Aug 24, 2011 11:37 am

Re: box2d + scene2d strange behavior

Postby TruePlayer » Thu Aug 29, 2019 7:46 pm

I can’t understand why the Y coordinate is shifted, moreover, this is only for the player, the ball and button is OK
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: box2d + scene2d strange behavior

Postby TruePlayer » Thu Aug 29, 2019 9:17 pm

VERY STRANGE CASES:

I changed the code a bit and now it:
Code: Select all
 stage = new Stage(viewPort);
        stage.addActor(testB);
        stage.addActor(player);
        stage.addActor(ball);
        stage.addListener(new ClickListener(){
            @Override
            public void clicked(InputEvent event, float x, float y){
                player.setPosition(x, y);
            }
        });
        stage.setDebugAll(true);


player behaves as expected, as I wanted, that is, appears at the point of touch with a finger
why does the gesture detector flip coordinates? or why is this happening? I need to use not a scene listener, namely a gesture detector for control
TruePlayer
 
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: box2d + scene2d strange behavior

Postby evilentity » Thu Aug 29, 2019 10:37 pm

Input processors work in screen coordinates. You need to unproject them to get world coordiantes with viewport. Screen has 0,0 in top left corner and y goes down. Libgdx has 0,0 bottom left and y goes up. This your flipped coordinates.
This doesnt happen in stage cus it does the unprojection for you. Also the listener converts the position to actors coordinates it is attached to.
Looking for a freelancer? PM me!
Check out libgdx discord server!
evilentity
 
Posts: 4854
Joined: Wed Aug 24, 2011 11:37 am

PreviousNext

Return to Libgdx

Who is online

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