Tag Info

Hot answers tagged

102

"Memory" and "efficiency" are commonly misused terms, so I'll give you an answer for four different elements that may affect the performance of your game. I will be oversimplifying way too many things to keep it short and concise, but there are tons of inaccuracies in this text below, so take it with a pinch of salt. However, the main concepts should be ...


16

Once an image is loaded off the disk and is formatted for rendering, it will use the same amount of memory regardless of whether that image was saved to disk using PNG, JPEG, or GIF. General rule of thumb: JPEG is a lossy format, and will degrade image quality in order to make the image smaller on disk. PNG, on the other hand, is a lossless image format, ...


12

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


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

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


8

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


7

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


7

Obviously not a lawyer, so this isn't legal advice, but my personal interpretation is: The code is licensed under Apache License, Version 2.0. If you read the Redistribution section: You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form... So, yes, ...


6

A map editor of some sort is what you are going to need (and want!) when your game moves more to the level design phase from the initial engine/coding phase. If you are using any kind of map/level editor, you will need to code a class (or set of classes) that can: Read/Input the Data Translate the data into actual objects (and sets of objects). Your tiles ...


5

Judging from a quick look at the libgdx wiki's SpriteBatch entry, alpha blending is on by default. Blending is enabled by default. This means that when a texture is drawn, translucent portions of the texture are merged with pixels already on the screen at that location. This means that you can do what you said: open the Hero texture in Paint .NET and ...


5

I don't know much about ouya but seeing the log, 01-02 07:09:21.490: W/PackageManager(305): java.lang.NullPointerException 01-02 07:09:21.490: W/PackageManager(305): at android.app.ApplicationPackageManager.putCachedIcon(ApplicationPackageManager.java:782) 01-02 07:09:21.490: W/PackageManager(305): at ...


4

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.


4

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


4

You want to set the texture's TextureWrap setting to Repeat. See the documentation for more information, and the texture method. Specifically: setWrap(Repeat, Repeat);


4

If you just want to target desktop and android devices, you can use the same networking library, as long as the library supports android. Kryonet is a networking library, that works both on desktop and android, and it is very easy to use (just look at the example from the page). If you want to implement networking also for HTML5 games, you would most ...


4

At this time, you'd have to create an int array of the layer indexes you do want to draw, and then use the render method which takes a camera and the layer indexes. So, if you have three layers and the last one is the collision layer you do not wish to draw, you'd do: int[] layers = new int[] {0, 1}; // preferably outside of the render loop, to avoid gc ...


4

You basically want the camera to walk around on a sphere. And you want the camera to look at the center of the planet while doing it. Or rotate the camera around it's target. Or implement an arcball camera.


4

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


4

Basically, the algorithm is as follows: Set maxBreak to the wrap length. If string is shorter than max break, return string. Set nextBreak to maxBreak and newString to ""and lastBreak to 0 Check if char at nextBreak is a break char (space, new line, etc.) If char is not a break char, subtract one from nextBreak and repeat step 4 If char none of the chars ...


4

In your touchDragged function you move the object a set distance. but you only seem to move the sprite based on its initial position, not the position of the touch. Shouldn't you move the object towards the X and Y sent into touchDragged so that it would end up under your finger? I would save the XY from touchDragged and send it to the object so that ...


3

In your main ApplicationListener where you create a camera object there will also be a resize method. If not override/implement it. It takes two arguments and when the window is resized these will be the dimensions of the newly resized window. Just set the cameras size to the new window size and call camera.update(); Should sort it! (I assume you are using ...


3

LibGDX has now added support for loading and rendering Tiled Map Editor's own .tmx file format. This should most certainly be your preferred method of loading and rendering TME created tile maps in LibGDX now, rather than having to manually parse through the JSON/XML data yourself. Link to LibGDX tutorial on using .tmx tile maps.


3

I believe that Tiled Map Editor (TME) can create files of different types, however the main feature that caught my eye was it's ability to export to JSON files. JSON is somewhat similar to XML and you will find good supporting APIs for parsing JSON files in Java. See here. Once you have created a map in TME you will be able to export it as one of these ...


3

Libgdx has built in decoding and encoding functionality. Gustavo Steigert has written a nice article about this on his blog: http://steigert.blogspot.be/2012/03/5-libgdx-tutorial-files.html. Scroll down a bit to the section "2. Persist Profile operation". In this blogpost, he explains that by using the class com.badlogic.gdx.utils.Base64Coder you can ...


3

Are you using bounding volumes for your objects? If yes then you could do something like this: boundingVolumes = GetBVIntersection(ray) foreach boundingVolume in boundingVolues (the model associated with the boundingVolume).Transform = boundingVolume.Transform triangles = GetTriangleIntersection(ray, model)


3

You must use texture coordinates instead of resizing, like draw only part of the whole texture. I don't know how it works in libgdx but it's common to use this approach. Another approach is to use texture atlas, you have in memory e.g 1024x1024 and then when you load your image you load it to atlas rectangle.


3

You just need to abstract your animation system enough that it doesn't care (read: know) where each frame of the animation is coming from. I have built one such system myself where each animation sequence is built up using a list of frames, where each frame is merely a rectangular section of some image. Using that set of definitions, the animation sequence ...


3

As ccxvii said, heavier objects do not fall faster. The only reason lighter objects sometimes fall more slowly is because the have higher air resistance. In a vacuum, all objects fall at the same speed. LibGdx uses Box2D for physics and Box2D is pretty realistic so changing mass will not affect how fast an object falls. However, there are two ways around ...


3

(a) To produce a "squash" matrix that smashes things to the ground plane parallel to a given sun vector, I would build it by composing two matrices: A shear matrix that maps the sun vector to +Y (straight up) while leaving the X and Z axes unchanged. A scaling matrix that scales Y by zero while leaving X and Z unchanged. Specifically, assuming you're ...


3

If you follow this guide: http://developer.android.com/training/articles/perf-tips.html Your method is the best approach, just remember to call the array from a reference that is in the same scope as your loop. Also, if possible, remove the "getHitBox" method, and get the object through public variables. Yes, this is ugly, but can be used in performance ...



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