Physics and scale in libGDX with Box2D - libgdx

I have a Image actor in libGDX that has a Body attached and is connected to another Body by a RopeJointDef to simulate a pendulum.
The problem is that the ball is moving very slowly:
The world gravity is set to -9.81f b2world = new World(new Vector2(0, -9.81f), true);
Increasing gravity force change ball speed but I want to be a 'real' simulation. I read in a post that may be because the pixel:meter ratio is 1:1. But I can't figure out how can I change this ratio without ruin the Stage. I would appreciate some help.

Take a look at this question and never do physics with screen to box2d in 1:1 ratio. Box2d doesn't like large numbers, you need to map in virtual pixels or sometimes known as potato pixels.

Related

LibGDX Hitbox / Polygonshape and Physics

Hello I have two smaller questions:
Is it possible to map the Shape of the Body 1:1 to the texture so I have a perfect collision detection ? Because right now I only know of two ways to do it: Create the Shape before and load it up with a texture or load the texture first and then set the shape as a box ... But that is too simple I think.
Also does anyone know how I can turn off the physics of the world ? When Body A hits Body B I want the Body to do a certain animation and fall to the ground with some sound effects, but when the two objects collide they bounce off each other in different directions etc. When two objects collide I want it to be "Game over" basically and stop calculating momentum etc.
I dont care about the solution itself, just telling me if its possible at all for both questions would be enough.
I guess you are using Box2d
Is it possible to map the Shape of the Body 1:1 to the texture so I
have a perfect collision detection ?
It possible, you can use PolygonShape in Box2D, but it has to be a convex polygon. Furthermore it slower then predefined shapes.
Also does anyone know how I can turn off the physics of the world ?
With box2d Physics you can simply stop the simulation on your own by not executing the world.step() command

How to create a circular constrained paddle using Box2D?

I am trying to create the ball and paddle setup just like in Circle Pong. It is basically a paddle which revolves about a circular path as if it is tied by a rope to the center of the circular orbit.
here is a video of Circle Pong: https://www.youtube.com/watch?v=9sitwBolywY
I want to use Box2D for the physics. How do I constrain the paddle to move in a circular orbit? I might even want to have multiple paddles for a circular orbit (with a fixed angular distance from each other).
A distance joint with a static central body won't work because the central body might obstruct / come in the way of the ball. Also it won't work with multiple paddles.
Any ideas?
for the first I'm not sure if you need physics engine in game like this at all - it seems to be such simple that simple scene2d actions + setting origins should be enough - please notice that it would improve your game performance and make it easier to deploy.
But - if you are sure you want to use box2d please consider using distance joint with a body which has a fixture with isSensor = true. It won't take part in collision calculations, letting you to achieve your point.
FixtureDef fixtureDef = yourMaterial;
fixtureDef.shape = yourShape;
fixtureDef.isSensor = true;

LibGDX: Inscribing a texture in trapezoid

Lets say I have an image of a spaceship and when it's moving from side to side it should be twisted by some angle. When it's steady and not moving it's parallel to the ground and to the viewports projection matrix. During the movement the shape of the spaceship for the observer turns into a trapezoid. So I am seeking for a way of distorting the image in order to "fit" it into a trapezoid. Here is an image for clarification.
This could be easily achieved by using PerspectiveCamera and 3D environment. The big trouble is that the game is already written using OrthographicCamera and 2D logic. Is there a way of solving this problem without creating a new set of animations and overwriting the whole project in 3D?

Creating a stage bigger then the screen view

I'm trying to create a stage which has an image of the background, called lvl1.jpg. This image is 1920x6000 pixels. I want to start the game by creating the stage and adding the player on top. I'm placing a few stationary enemies on the level which the player should avoid.
I want to achieve this by letting the stage (or background image) and the enemies moving up a few pixels with each update. The size of the game file screen is 1000 by 600 pixels. So my gameclass is larger then my screen size will be. Is this possible? If so, how can I achieve this?
Yes, it is possible, but you should not directly use such a big bitmap anywhere, it's killing performance. And yes, it is possible for the game class to be bigger than stage size, look at Epic War 2 game for an example - it has a big battle scene that scrolls left-right on demand of the player.
In order for you to make such a game class, you should limit the actual screen presence to only the visible parts of your level. For this, research blitting techniques, which have a core concept of one visible Bitmap object with the size of a stage, whose BitmapData is redrawn each frame to display background, objects, player, monsters, etc.
As a first approach, you can have your Game class contain all the objects, including player, and change game.y so that the player is always within the stage boundaries.

as3 movieclip antialias

I kept a bitmap inside a movieClip, bitmap has been set to be smoothing. but when I changed the scale of this movieclip, it still got pixelated. Do we have the way to avoid. it is really painful.
When you scale bitmaps, quality gets lost, always.
Always snap x and y positions to full pixels.
stage.quality = "best" gives you better anti-alliasing (bicubic), but it cost more CPU.
Try to find out what the maximum scale of the image could be. Then make the image at that size.
Most people dont't see its not that smooth, just make the game runs smooth and fun. so relax about it.