Hot answers tagged

4

Tiled does support drawing lines as collision objects. To do this, you should just not close the polygon (right-click once you're done with the polyline). In the past these have been separate tools, but in Tiled 1.2 they have been unified into a single tool. Probably the UI needs to be more clear that the tool can be used to create both polygons and ...


4

The Greek philosopher Zeno proposed a paradox: an arrow can never strike its target. In order to do so, it would have to: First, cross half the distance to its target. Then, cross half the remaining distance (one quarter of the original distance) Then, cross half that remaining distance (one eighth of the original) Then, cross half of that remaining ...


3

If you don't need the deceleration to be the same fixed amount each frame, you can instead apply a "drag multiplier". This is used in many games as a crude approximation of air resistance, where the faster you go, the more air you have to push through per unit of time, increasing the friction at high speeds. public float velocityMultiplier = 0.95f; ...


2

Accepted answer is good, but I couldn't use ShapeRenderer as it need to be used on closed batch. In that case you can use ShapeDrawer which is ShapeRenderer that can be used on open batch.


2

To do it programmatically without having to keep track of all the keys: Preferences prefs = Gdx.app.getPreferences( "your_preferences_name_here" ); // Clears the values prefs.clear(); // Saves the change prefs.flush();


2

LPDIRECT3DTEXTURE9 is a texture object. OpenGL, by comparison to Direct3D, is weakly-typed, so there is no class or struct that is equivalent; instead texture objects are represented by unsigned integer "names" - the same GLuint data type that is used for other object types. From the code you posted it looks as though you're trying to set texture data from ...


2

Think of the gun as of being parented to the player (conceptually, it inherits player's transform (rotation)). That way, you only need to worry about the local angle (in local space, it's as if the orientation of the player never changes). It's because in 2D, the angles simply add up - see the image below: So you can still use Math.max(Math.min(...


2

Having a constant time-step does not mean that you force your client to update exactly 60 times per real-life second, it means that whenever you update your physics the timestep you send to your physics engine must have a set value (in this case 1/60th of a second). In other words your code is mostly correct: TIMESTEP = 1 / 60; accumulator = 0; update(...


1

Adding the dragged actor's parent coordinate values to the actor's values did the trick: Vector2 snapShot = new Vector2(a.getParent().getX() + a.getX(), a.getParent().getY() + a.getY()) ; other.getParent().addActor(a); a.setBounds(snapShot.x, snapShot.y, a.getWidth(), a.getHeight());


1

Two obvious problems here: You've labelled a variable degree that's actually measured in radians, not in degrees. You're telling the object how much to rotate by, not giving it a target angle it should rotate to. These can both be solved by reading the documentation for the methods you're using. It tends to show when you don't. 😉 float radians = (float)...


1

You are probably using Gdx.graphics.getHeight() to change orientation of vertical axis from recieved click. If this is the case following code should work correctly: Vector2 bulletDirection = new Vector2(screenX - player.getX(), (Gdx.graphics.getHeight() - screenY) - player.getY()).nor(); Also there is better way using unproject described here as it will ...


1

There are many ways to get to this, and you might need several iterations over the architecture before getting it right. Because of this, this answer will be quite broad. You could consider your game from three different points of view: the simulation, i.e. what happens in the game the 3d render of the game, i.e. the display of how is your world organized ...


1

Wrapping a tiled map can be achieved by rendering the TiledMap multiple times if the camera position is closer to the borders of the map than the size of the camera viewport. So for example on a map that is 16 world units wide and viewed by a camera with a viewport width of 8 and the camera is at X=2 then the map needs to first be renderer as normal using ...


1

Implement continuous collision detection. Inverse square law means the velocity while approaching an imminent collision is asymptotically high. One frame the object is on one side, and translating it to a new position will place it on the far side of the object, as if there were no collision. This is called tunneling. Continuous collision detection is for ...


1

If you use a bounding circle for the player then the "dead zone" can be defined as whenever the line-of-sight ray from the gun to the target intersects with the circle. Detecting that the gun is intersecting the player is simple, in libGDX the Intersector.intersectSegmentCircle method is useful for this. What is harder is to rotate the gun so that ...


1

Playing sounds from the beginContact, endContact, preSolve and postSolve methods is not a good idea (as you've identified) as the methods may be called many times per World step depending on the number of collisions that occurred. What you can do in these methods is to collect information so that you can use it later when the Box2D World step is done. One ...


1

Setting the transform directly can lead to weird results (as you point out yourself), and it's often better to control your bodies using impulses, even if it is sometimes difficult to tune it to perfection to get just the sort of movement you're looking for. Depending on the kind of movement you're looking for I'd recommend using applyLinearImpulse to move ...


1

I found the solution in a badlogic forum. This: modelBuilder.part("minecraft:loading_model", mesh, 4, new Material(TextureAttribute.createDiffuse(atlas), blendingAttribute, FloatAttribute.createAlphaTest(0.95f))); Or this: modelInstance.materials.get(0).set(FloatAttribute.createAlphaTest(0.95f));


1

I managed to solve the problem myself but it still seems like it may be a bug. It happens because glyphLayout.setText(font, text); is declared in the constructor method but it needs to be in the render method, or otherwise continually updated. I've no idea why this is, it would seem that declaring it once in the constructor method should work fine...but for ...


1

I want to share with you how I handled it finally. I shoot a "ropeBullet" which is small circular box2d body, by setting it's velocity and angle. I render a rope graphic between bullet and ball. When bullet reaches wall, I get from contactListener the point of contact I connect the bullet and the wall with revoluteJoint, based on bullet center and contact ...


1

I know that this is a very old thread but I just made my own way of getting the size of a Body here: https://github.com/Wasupmacuz/Box2DBodySize Here's the code if links are too spooky for you: import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.ChainShape; import com.badlogic.gdx.physics....


Only top voted, non community-wiki answers of a minimum length are eligible