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


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


9

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 upon is that their static properties are global variables and globals cause all kinds of problems architecture-wise. For example, when you ever decide you might ...


8

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


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


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() { //...


5

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 draw rate of the monitor, typically 60 Hz; this is due to the fact that there is no need to ask to draw faster than what the monitor is able to process. By ...


5

Since Steamworks is a C++ API, you'd need to write a wrapper. You can use the Java Native Interface (JNI) for this, or possible the Java Native Access API instead. The JNI is the "classical" method, the JNA thing seems to be newer and I know less about it. The Steamworks SDK is not public, so I can't link you directly to the interface you'd want to wrap, ...


4

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


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

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


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


4

I've run into this kind of trouble a few times, but not yet on 3d. First of all, I'm not really sure you transformed correctly the acceleration formula... maybe this source can help in that way. Secondly, at the end of your post you mention you want to specify a specific TIME for the sprite from one point to the other, if that is your goal then you should ...


4

The Android memory profilers that comes with the Android Developer Tools will allow you to figure out what is consuming your memory. It comes in three parts; Memory Monitor (this is used to find performance problems, so we can ignore this one for this particular problem). Tool Heap Viewer Allocation Tracker Using the Heap Viewer you can take snap-shots ...


3

As @user3068350 said, both Game and ApplicationAdapter implement ApplicationListener. It's useful to extend Game if you plan on using the Screen interface in your game, however some developers may wish to take a different approach and handle screen management their own way. If this is the case, these will extend ApplicationAdapter. Personally, I like my ...


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 don't believe there is a built-in function for this. You have a few options though: Use a 9-patch for table background with a border (thats what I do) Place another table underneath the main table, and make the size a bit bigger so you can see the edges, giving the impression of a border. This is probably your best choice since you want to control color/...


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); shapeRenderer.begin(...


3

I hope I am understanding your question correctly -- if not let me know. I believe the following is where you are unprojecting the coordinates: @Override public boolean mouseMoved(int screenX, int screenY) { worldCoordinates = camera.unproject(new Vector3(screenX, screenY, 0)); return true; } Because you are using a viewport, you must add the ...


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

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


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.



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