Hot answers tagged

78

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 sorts of things. Making flat things look like they have a third dimension. You don't even have to change the height of the ball, you just need to change the ...


42

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 random colours), and scrolling it across the display geometry over time. Instead of drawing the colours from this texture, I instead take the red & green ...


24

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 StackExchange. Here's two copies of Mario - both are moving across the screen at the same rate (either by the sprites moving right in the world, or the camera moving ...


19

TiledMap tiledMap = new TmxMapLoader().load("path/to/tiled/map.tmx"); MapProperties prop = tiledMap.getProperties(); int mapWidth = prop.get("width", Integer.class); int mapHeight = prop.get("height", Integer.class); int tilePixelWidth = prop.get("tilewidth", Integer.class); int tilePixelHeight = prop.get("tileheight", Integer.class); int mapPixelWidth =...


19

First, Texture vs TextureRegion: When you do something like Texture t = new Texture(path), you are loading that into GPU. In addition, you should load power of 2 textures. You could work with other resolutions (Texture.setEnforcePotImages = false), but it's encouraged to use pow of 2. Now, TextureRegion, takes a "piece" from a Texture, no matter it's ...


19

It defaults to locked on "landscape" mode in a libGDX project. You need to go into your "AndroidManifest.xml" and change android:screenOrientation="landscape" too android:screenOrientation="sensorLandscape" There are more options - http://developer.android.com/guide/topics/manifest/activity-element.html#screen Just replace "sensorLandScape" with the one you ...


18

Think of the problem like this: How does a snake move in the original game? The snake moves towards its current direction. The behavior looks like the head appears out of nothing, and the last tail part disappears. You can have a list of snakeparts. What you want to do is remove the last item in the list which represents the last tail part. Then you want ...


17

It's easy: Fonts do not need to match resolution, they need to match pixel density. Pixel density is measured as pixels per inch(PPI), or pixels per centimeter. There's also a measure unit called density independent pixels(DP). It is defined that 1dp is the size one pixel has on a 160 PPI screen. Now coming back to fonts, try to make this test: put your ...


16

You seem to want to keep the same textsize/screensize ratio. Basically what you do is develop at one resolution and let that be scale 1.0. Then you divide the new screen width by the old width and that is your scale factor. For example. Developing on 2560x1440 with font size 16 and running on 1920x1080. Font size will be: 1920 * 16 / 2560 = 12 I do the ...


16

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 map render target would be the size of your tile map, but in pixels. Each pixel would represent the light color of its corresponding tile. This render texture ...


15

When the ball (red trajectory curve) hits a block higher up (blue rectangle), it will be moving slower than when it hit a block lower down (green rectangle). Hence why it doesn't bounce any higher than where it came from. Physically, this makes sense. Doodle Jump obviously isn't physically accurate. If you want an effect like in Doodle Jump where the ...


15

After banging my head against this problem for a day I found a wonderful tutorial on the very subject over at Sion Dream. I knew there was a way to use object layers! In a nutshell, create an objects layer on your map (Tiled, Tide and the tutorial author's pick, Gleed, all provide this function), draw the shapes you want your Box2d static bodies to be, then ...


15

As someone who has recently released a libGDX game on Steam, unlike .NET and DirectX, Steam does not provide an option with your application to automatically check and download the version you need of those libraries. It's obtrusive to the user to make them install Java as a system library, as most still view the JRE, especially Oracle's, as some kind of ...


14

There was a post explaining the changes, but is not easy to find. The link was on the 1.5.6 release changelog: http://www.badlogicgames.com/wordpress/?p=3666 And the link about changes in fonts was: http://www.badlogicgames.com/wordpress/?p=3658 private static GlyphLayout glyphLayout = new GlyphLayout(); private BitmapFont fontA = new BitmapFont(), fontB = ...


13

Alright, so you're working with two rectangles here. A larger static one (the map) and a smaller moving one (the camera) inside of it. What you want is to not let the bounds of the smaller rectangle move outside the inner bounds of the larger rectangle. // These values likely need to be scaled according to your world coordinates. // The left boundary of ...


13

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 screen unchanged for at least a few seconds. When you want to display a text, render that text to a texture once and then draw that texture instead of re-rendering ...


12

Ignore all the /bin/ directories (they contain files generated from sources). The /war/ directory hierarchy is similar (generated files for the GWT/HTML backend). You can ignore the /.settings/ directories, as they contain Eclipse settings, and are not required to be able to re-build your application. (These are probably a bad idea to push into git if you ...


12

Since you can read the device density and render fonts during runtime in libgdx, I use this solution to achieve a density independent font size: float densityIndependentSize = origFontSize * Gdx.graphics.getDensity(); int fontSize = Math.round(densityIndependentSize ); BitmapFont font = generator.generateFont(fontSize );


12

This is a problem pretty much everyone faces when getting into LibGDX. What you need to remember as you code is this: pixels are bad. Down with pixels. Because you're using a camera object to determine how/where to draw your sprites on screen, you can set your game's world to use any units you want, and scale to each screen just by constructing the camera ...


12

This has changed once again. The correct code for the method is currently as follows, as stage.setDebug() has seemingly been removed (can't find what version that happened) and replaced with stage.setDebugAll(true);: @Override public void render(float deltaTime) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); if (...


12

Here's a vector-based solution. I haven't tried it, but it seems fine conceptually. Theory I gather you've stored the shape as line segments. Here's the letter A represented with three line segments. I've assumed that paths in the user's drawing are stored as lists of points. We can "inflate" those line segments to allow an error margin when checking for ...


11

The new project generator comes with autogenerated .gitignore file like: ## Java *.class *.war *.ear hs_err_pid* ## GWT war/ html/war/gwt_bree/ html/gwt-unitCache/ .apt_generated/ html/war/WEB-INF/deploy/ html/war/WEB-INF/classes/ .gwt/ gwt-unitCache/ www-test/ .gwt-tmp/ ## Android Studio and Intellij and Android in general android/libs/armeabi/ android/...


11

There are a few potential problems here. Lets take a look at your code first: if(arg0>0) iX += 20; else iX-=20; arg0 is the velocityX of the last known horizontal velocity of the finger in pixels per second. Here's the method signature for fling(): fling boolean fling(float velocityX, float velocityY, int ...


11

Create an AssetManager: AssetManager manager = new AssetManager(); This to begin the loading: manager.load(FILE_SPRITE_ATLAS, TextureAtlas.class); This getting called continously for asynchronous loading: manager.update(); Or this called once for synchronous loading: manager.finishLoading(); and then this saves the spriteAtlas (when update() returns ...


11

Dialog is better suited for modal pop-up windows, and it includes a "button" and "content" table already in the window (as the docs say). You can grab these tables with getButtonTable() or getContentTable(). The dialog makes it easy to work with pop up windows. For example, here is a confirmation dialog: Dialog dialog = new Dialog("Warning", skin, "dialog")...


11

v1.7.0+ Pixmap pm = new Pixmap(Gdx.files.internal("cursorImage.png")); Gdx.graphics.setCursor(Gdx.graphics.newCursor(pm, 0, 0)); pm.dispose(); Before v1.7.0 Pixmap pm = new Pixmap(Gdx.files.internal("cursorImage.png")); Gdx.input.setCursorImage(pm, 0, 0); pm.dispose(); The hotspot parameters represent the "tip" of the cursor. For example, the operating ...


11

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 designing your shape as relative positions around some origin point. Now you need to calculate how the shape will expand. To do this we simply calculate the ...


10

You can call .setText("Some String"); on your label in your Render-method.


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