Hot answers tagged

75

Give the ball a height value. Draw a shadow at the ball's actual 2D position; the shadow will help spatially orient the ball for the player. When you draw the ball itself, offset the Y position by the "height" of the ball. If you want to implement more than just an illusion, use this height value in computations as well -- for example, you can implement the ...


74

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 ...


31

Welcome to open source! As most developers will tell you: "What documentation?". Documenting code is probably the least fun developers have when creating a project. So what do you think is often severely lacking when the developer isn't even getting paid for their creation? Documentation of course! (Even fully paid programmers will often leave out the ...


29

I think you're after Application querying switch(Gdx.app.getType()) { case ApplicationType.Android: // android specific code case ApplicationType.Desktop: // desktop specific code case ApplicationType.WebGl: /// HTML5 specific code }


20

As usual I'll just throw a few ideas to the table. There are certainly several ways you can approach this problem. I'll describe the three I managed to remember, and it's up to you to decide which (if any) of these approaches is good for your project. Idea 1: Repeatable patterns in your tiles Does your system need to be flexible enough to support any ...


19

Storing the completion information in a local file is a simple and perfectly acceptable method of doing so. Fundamentally, this is what every game will do to track progress (in some fashion, although the specific formats used for the data and the storage mechanism will differ). Protecting the file from tampering is more difficult. If there's no compelling ...


18

From my little experience with box2d in libgdx, it can sometimes be difficult to isolate and resolve issues with exceptions which was only worsened by the latest port. Pre 2.2.1, I could easily remove bodies from the world without synchronization issues like you are experiencing but after migrating to the libgdx build that supported 2.2.1, I started seeing ...


18

As Byte56 said, in libGDX you cannot play videos :( so i did this: I created a new activity "SplashScreen" public class SplashScreen extends Activity implements OnCompletionListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); String ...


17

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 ...


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

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 ...


13

I agree with @Byte56 that you may be better off with something a bit simpler than Android game development, however for completeness (if other people would like to know where to look): http://steigert.blogspot.com.au/2012/02/1-libgdx-tutorial-introduction.html Steps through several different aspects of development with libgdx, from setting up your project, ...


13

You can just use another SpriteBatch without setting projection matrix to draw the HUD, camera.update(); spriteBatch.setProjectionMatrix(camera.combined); spriteBatch.begin(); aButton.draw(spriteBatch, 1F); playerShip.draw(spriteBatch, 1F); spriteBatch.end(); hudBatch.begin(); //Draw using hudBatch hudBatch.end();


13

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 =...


12

It's basic physics: heavier objects don't fall faster! A feather has a bigger area than a pebble; hence it gets slowed down by air resistance a lot more. Introduce a drag force that slows down objects the faster they fall, in the opposite direction of the velocity. The drag force will cancel out gravity once terminal velocity has been reached. drag_force = ...


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 ...


11

Create a triangle strip. You could have your random heights at intervals equal to t. So the triangle strip would then consist of you alternating between the height vertices (with y being random and x equal to t * iteration) and vertices that go along the bottom (with y being constant and x also equal to t * iteration). Naturaly, the distance between each ...


11

Playing video with LibGDX has been defined as out of scope for the project. So no, you cannot play videos using LibGDX. This does not preclude the possibility of writing code specific to Android to play videos though. It just means your application won't maintain the portability of LibGDX.


10

I decided to go with libGDX for similar reasons. To expound on my comment, I will mention what I find are the pros and cons. Pros: Works on Android and desktop (no need for emulator) Active user community on forums Lots of robust functionality Works on iOS too (via RoboVM => free) Cons: Lack of documentation and information Quite low-level (I prefer ...


10

The reason you're limited to power-of-two sizes is due to how video ram works. Note that what you should do is typically make the image the next highest power of two (.e. 512x256), and then just use a portion of that image for your graphics. You'd be setting your UV coordinates to only use a subsection of the image onto whatever triangles you're rendering. ...


10

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 ...


10

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). 1dp is the size one pixel has on a 160 PPI screen. Now coming back to fonts, try to make this test: put your laptop to run on 720p....


10

The PNG files are small because they are compressed. When the images are loaded into memory they are uncompressed and therefore take up more space.


10

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 ...


10

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 = ...


9

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 );


9

First off, what is the difference between say Body.getWorldCenter() and Body.getPosition(). Body.getWorldCenter() is the center of gravity. Body.getPosition() is the center of the AABB. For a simple box or circle they will be the same however if your body is unbalanced (ex. multiple fixtures /w different densities) they will differ. Also try setting your ...


9

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/...


9

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, ...


9

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 ...



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