Hot answers tagged

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.2k
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
  • 134k
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
  • 134k
15 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,394
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
  • 119k
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,840
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
  • 119k
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

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
  • 134k
8 votes

How do I render a rounded rectangle in libgdx?

In case it's useful for anyone, here's my extension of LibGDX's ShapeRenderer to draw rectangles with rounded corners, using Josh Petrie's approach of drawing five rectangles and four arches. I ...
jlcontreras's user avatar
8 votes
Accepted

Profiling LibGDX game with GLProfiler

You seem to lack some insight on your issue. A couple of things to consider: Is your true maximum frame rate on your PC really 60 or is it more? NVida drivers limit the frame rate to the maximum ...
Vaillancourt's user avatar
  • 16.3k
8 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,840
7 votes

LibGDX : Textfield input type

I found out a solution to your other problem. To allow the typing of a dot you should create your own implementation of TextFieldFilter like this. ...
Zigur's user avatar
  • 93
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
  • 469
7 votes
Accepted

How do I check for collision between an ellipse and a rectangle?

I'm going to tell you how to do it with a computationally cheap way in terms of CPU usage. First, let's say that the calculation of seking if a point is "inside the ellipse or not" is not ...
Xavi Montero's user avatar
  • 1,063
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
  • 330
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,461
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,461
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,265
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

How do I make an on-screen HUD in libgdx?

I have done it like this: First i have created a new Class called Hud. It implements Disposable because of the resource management. Then you need to define a ...
Bexx's user avatar
  • 68
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,840
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,522
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

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