Skip to main content
77 votes

How can I give the illusion of height to a ball in 2D?

Shadow and texture. Texturize the ball to show it rotating. This helps give the illusion of rotation of a sphere, which is more than 2 dimensions. A shadow can trick your brain into believing all ...
House's user avatar
  • 73.3k
42 votes
Accepted

How to animate abstract 2d top down water texture?

A common way this is done is using an indirect texture lookup in the shader to distort the display texture: Here I'm using a texture with some low-frequency colour noise (tiling smooth blobs of ...
DMGregory's user avatar
  • 135k
27 votes
Accepted

How do I move the camera in full pixel intervals?

Your problem isn't moving the camera in full-pixel increments. It's that your texel-to-pixel ratio is slightly non-integer. I'll borrow some examples from this similar question I answered on ...
DMGregory's user avatar
  • 135k
16 votes
Accepted

How can I implement smooth tile-based lighting?

A simple way to achieve smooth lighting in a tile based game, is to draw a "lightmap" to a render target, and then drawing this render target over top your scene while alpha blending it. Your light ...
jgallant's user avatar
  • 8,424
13 votes
Accepted

Is it reasonable to use FreeType

If you use a font rendering engine like FreeType, then the most common mistake is to re-render strings every frame. This is pointless, because when you render a string, it will usually be on the ...
Philipp's user avatar
  • 120k
10 votes

How can I make expanding bullet pattern shapes?

The easiest way to do this would be to first design the shape then calculate the movement of the particles. In this answer I will be constructing a square, but this applies to any shape. Start by ...
Charanor's user avatar
  • 7,870
9 votes
Accepted

Main game objects as static

It won't hurt performance. It might in fact be (very, very negligible) faster because you save the overhead of passing these objects to the game objects. The reason static classes are often frowned ...
Philipp's user avatar
  • 120k
9 votes
Accepted

LibGDX simple button with image

A drawable has information about its size and how to draw itself. It's used to determine size and position by ui components. Since you are using a texture, you can use a TextureRegionDrawable. ...
user3068350's user avatar
9 votes
Accepted

What is the difference between expand(), grow() and fill() in libGDX?

Expand: expands the cell that the actor is currently placed in to occupy the largest possible area without changing other cells size. For example if the cell is <...
Charanor's user avatar
  • 7,870
9 votes

Why do separate loops run faster than one loop that does multiple things?

This is not an unexpected result actually. It's a little like how a person's efficiency plummets when they try to multi-task, compared to when they can focus on doing one specific job. Modern CPUs in ...
DMGregory's user avatar
  • 135k
7 votes
Accepted

How to scale LibGdx TextButton?

A little late but to answer my own question, you have to setTransform(true) if you're scaling a Button or ...
Neerkoli's user avatar
  • 479
7 votes

LibGDX simple button with image

Something like this should work; ...
Jax's user avatar
  • 410
7 votes
Accepted

Difference Between LibGDX and LWGJL

LibGDX is based on LWGL and its advantage are that a lot of the base stuff is already written and you don't need to write it. Some people prefer to write it themselves though. LibGDX is generally used ...
ProRed's user avatar
  • 340
7 votes
Accepted

Is it possible to use animated .gif images in lbgdx?

There is a GifDecoder class that turn a .gif file into a libGDX Animation. With it, you can render animated .gifs like this; <...
bornander's user avatar
  • 4,516
7 votes
Accepted

LibGDX - My sprite glitches when it moves

It happens because you update the camera's position out of sync with the player's position. In public void render(float delta) ...
bornander's user avatar
  • 4,516
6 votes

In LibGDX, how might I make an object orbit around a position?

If you wish for an object to orbit around a specified point in two dimensional space, you want to use some trigonometric functions. Here is an example method to calculate an objects position in an ...
Aidan Lovelace's user avatar
6 votes
Accepted

How to create a projectile motion of a cannonball in top down view?

From wikipedia: $$d=\frac{v_0^2}{g}sin(2\theta)$$ When you reverse the formula to find the angle from the distance and initial speed, it becomes: $$\eqalign{ d&=\frac{v_0^2}{g}sin(2\theta) \\ ...
starikcetin's user avatar
  • 5,295
6 votes
Accepted

How to bend a 2D rectangle in an animation?

Background info on rendering textured polygons using the GPU The approach you mention, adding extra vertices is the correct one. In 3D animation, it's the vertices of a mesh that are adjusted during ...
Jelle van Campen's user avatar
6 votes
Accepted

What is the difference between a Listener and a CaptureListener in LibGDX Scene2D

According to the official LibGDX wiki, capture listeners are called before "normal" listeners to give you a chance to intercept the events. (i.e. Active window cancels click on button under ...
Winter's user avatar
  • 341
6 votes

How to animate abstract 2d top down water texture?

This is called a caustic effect, and generating these effects at runtime is fairly time consuming, so this is traditionally done with pre-rendered frame-by-frame animation. There are tools that will ...
Ed Marty's user avatar
  • 5,229
5 votes

Confused about using libGDX dispose()

Dispose() is not called automatically. You have to call it manually whenever you with to dispose a texture (or anything that implements disposable). The only ...
Charanor's user avatar
  • 7,870
5 votes

How to use Actors/Groups with ShapeRenderer instead of Batch?

Here is my HorizontalLine class. If you create one, set it's width and weight (height) and you can add it to a container like ...
Jacob's user avatar
  • 2,552
5 votes

Spritebatch and Shaperenderer

From this topic: http://badlogicgames.com/forum/viewtopic.php?t=8573&p=38930 You should try not to do the following: (Quote from one of the GDX creators) ...
Jacob's user avatar
  • 2,552
5 votes
Accepted

What technique should I use in a shader to give this reflective effect?

Well, a good approach would be to create a bit mask, where the time a specific pixel should be fully lit is indicated by the amount of red it contains. So for example a pixel would be completely ...
Bálint's user avatar
  • 14.9k
5 votes
Accepted

How to move Stage in LibGDX?

You should not move the stage, you should move the viewport for the stage. You need to make sure when you call this ...
benh's user avatar
  • 581
5 votes
Accepted

Avoid unreachable rooms in duengons

It depends on what algorithm you are using to generate your dungeon. There are algorithms which by their very nature ensure that everything is reachable: Algorithms which start with one room and then ...
Philipp's user avatar
  • 120k
5 votes
Accepted

Need help with getting a direction vector between two given points

In your situation you need a simple subtraction, with a normalization. vectDistance = B - A vectDirection = vectDistance / lenght(vectDistance) This will give ...
Vaillancourt's user avatar
  • 16.3k
5 votes
Accepted

2d Collision detection libgdx

A different approach for collision resolution Good question, your workflow seems to be the: (1) move the player, (2) check if the player is inside a wall, and (3) try to push the player out of the ...
Jelle van Campen's user avatar

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