Hot answers tagged

9

TextureAtlas#findRegion(String) returns a region with a name that matches the name specified. It does not copy the region, therefore any changes you make to the region will be reflected in the TextureAtlas. To overcome this issue, simply instantiate a new TextureRegion object and pass it the region found inside your TextureAtlas: background1 = new ...


8

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


8

I am not familiar to the particular engine you are working with, but in most languages or cases you can use a 1xn matrix (i.e. a vector) where n is the total number of NPCs, that stores the 1-or-0 values, so the position within the vector is related to the NPC number. For instance, in pseudo-code: already_talked = {1,0,1...n} //where n is the total number ...


6

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


5

What's happening First of all, note that this behavior is not specific to oblique collisions. Below is an example of two balls colliding head on with a wall. All fixtures have m_restitution = 1.0, and m_friction = 0.0. The ball on the left is traveling with v = 0,1 and the ball on the right has v = 0,1.01. I found three similar questions asked on the ...


5

Don't keep newing up TextureRegions, try re-using one and just change the parameters of that. private TextureRegion bgRegion; public void create() { bgRegion= new TextureRegion(bgTexture, -1 * (int)bgObj.getX(),0,256,240); //bgObj is a scrollable object where in each update changes X value of position(Vector2): moves left. } public void draw() { ...


4

The artifacts are caused by scaling the images using point sampling / nearest neighbourhood filtering, which effetively doubles some of the pixels from the original image. To get better results, switch to bilinear filtering which uses weighed average of multiple pixels. The result will be a little blurry, but should look a lot better than the current one. ...


4

Alpha mask texture approach In case your circle would always be the same size, using a second alpha mask texture would be the way to go. You would make it a grayscale mask texture and use its value as the alpha value while drawing. Using a texture had the benefit of having anti-aliasing built into the mask (ie. at the borders of your circle, the pixels can ...


4

The problem you are facing is conversion between two different coordinates systems: the graphical one and the input one. Graphics coordinates Like you said, libGDX uses a 1 to 1 ratio between space coordinates and pixels, and starts in the bottom left corner. But it can be anything, really. That is just the default behavior of libGDX. You could change the ...


4

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 computationally cheap, while comparing just rectangles with mere "greater than" or "less than" comparisons are ultra cheap. Definition 1) Ellipse and its quadrants If ...


4

You are specifying a time in seconds as an integer value, but you are not taking into account the game's frames per second. If your game was running at 1 frame per second, it would work, because after two frames (thus, two seconds), your object would have travelled the specified distance. It's a simple case of multiplying your time by your FPS: int dst = ...


4

If I understood you correctly, instead of defining "canTalk" as a boolean, you can just define it as an integer and start by assigning it either a NULL value or a -1. Then when the player is within the square range of any of the NPC, you just assign the canTalk = NPC index (0,1,2...n where n is total number of NPCs). Then, you set the dialogue function to ...


3

To implement a spring I would do this: On the spring-player collision detection Give an impulse to the player toward the desired direction Disable the spring Let the gravity take care of the rest Re-enable the spring after on or more conditions: After a certain delay After the player is no longer colliding with the spring After the player is ...


3

I think it will work if you combine your input listener with: animation.isAnimationFinished(stateTime); While playing animation ignore attack input and let it just continue playing. When the animation finishes you can respond again and start a new animation by reseting the stateTime. But I would also have in mind that the player can move meanwhile and ...


3

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. public class DigitFilter implements TextFieldFilter { private char[] accepted; public DigitFilter() { accepted = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.'}; } @Override public ...


3

If you would follow the second strategy, changes made to the Vector that got passed as parameter "v" will also be made to "vector2", since they are the same object. You should have a look at this question: http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value In Java every object is an reference, so you need to copy, for ...


3

As mentioned above, you can start and stop a SpriteBatch in the same draw-method, also for transparency you need to enable BLEND. Here's what I did with one of my UIs. batchstuff... spriteBatch.end(); Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); ...


3

This is because movementSpeed should be how many units you would like your character to move per second (so your movement speed should be 6, for 6 units per second), and multiplying that by deltaTime in LibGDX will give you a value that will achieve the movement of movementSpeed per second. Delta times work differently depending upon how they are ...


3

I found the solution, so I think I should write here for other ones later. First I download the source code of box2dlights. Then open BaseLight.java and find "segments" member variable. This variable contains all information about what I was finding. This code below is just for debugging purpose: rayHandler.setCombinedMatrix(camera.combined); ...


3

Try this: @Override public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) { super.keyboardFocusChanged(event, actor, focused); if (!focused) setOnscreenKeyboardVisible(false); } Otherwise you could go for a better work around. You place a big clickable transparent actor behind everything. When you click anywhere ...


3

In the second case it is not drawing because the constructor with no arguments doesn't set a width and height for the image, however the constructor that takes the drawable obtains the values from it. To fix in your case: Texture texture = new Texture(Gdx.files.internal("cookie.png")); Image itemImage = new Image(); itemImage.setPosition(10, 10); ...


3

A lot of great Libgdx extensions have been added to the maven repository such as freetype, tools and many other great libraries. This means you can add extensions in a blink of an eye, at least if you used the gradle LibGDX setup. In your case you want to add freetype, look it up in the link above and select the version you need. Now select the tab Gradle ...


3

One option is to use a wake lock. Example from the docs: PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wl.acquire(); // screen and CPU will stay awake during this section wl.release(); I've got this answer from this stack overflow post. ...


3

Try turning on the grid in Tiled (Ctrl+G) and adjusting your "Tile Side Length" in the Map Properties so that the grid matches correctly with your tiles. It may fix the libgdx rendering issue, and would improve the mouse picking in Tiled a little. I know setting up a hexagonal map (and even an isometric map) is somewhat confusing at the moment. It's ...


3

Move this after the for loop: dispose(); ((Game) Gdx.app.getApplicationListener()).setScreen(new GameOver()); You create/set a new GameOver Screen each iteration, that causes probably the freeze and problems.


3

If you just dispose the sound, you're trying to play something unexistent. Also, this is a bad practice because you're constantly creating and destroying a sound when playing it, and that's not needed. Try to get the dispose to the end of the game, place your sound somewhere available and just play or stop it when needed. This is some sketching code, not ...


3

RTS's are probably one of the hardest game genres to make because of the huge amount of balancing that has to be done between different units, then on top of that multiplayer adds another layer of complexity... for example look at GreyGoo an RTS made by a proper development studio, they had the experience to balance the game but because of networking ...


3

Delta time should not be used to calculate velocity, but position. When you set velocity.y to speed, you are saying "My character will move <speed> pixels per second in the y axis". Later, when you update the actor's position you will calculate the y position by character.position.y += velocity.y * deltaTime; An easy way to think about this is ...


3

Disposal patterns like LibGDX's in languages with GCs often have to do with releasing un-managed resources in addition to (or instead of) managed memory. This true with C#'s IDisposable interface, and based on the documentation LibGDX's pattern serves a similar purpose. This means that simply looking at private working-set CPU-side RAM use may not be an ...


3

I don't know about writing an error log on crash, but all Android apps already log to the built-in logger. You just need an app like CatLog to view them. Although verbose, you can usually filter by namespace (and see logs only related to your application). Eclipse does something similar with the built-in log viewer. This is the only log viewer I used when ...



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