Tag Info

New answers tagged

1

Are all coins doing the same animation? You could make a method in the Animation class that takes a coin as an argument, then performs the animation on that coin. Then, on another class, you make a loop that traverses the coin list and calls the method in your Animation class, therefore animating each coin as you go through the list. You can also add delay ...


0

This is how you can calculate the delta time and move a sprite FPS-independent @Override public void render() { position += Velocity.nor() * Gdx.graphics.getDeltaTime() * speed; }


0

You can also take a look at one of Notch's LD game's source code. He implemented the behaviour you are talking about in this project: Minicraft


0

If you ignore the constants you have in your calculations (such as tile width, for example) the calculations for isometric to cartesian and back are usually; float isometricX = cartesianX - cartesianY; float isometricY = (cartesianX + cartesianY) * 0.5f; And the reverse is float cartesianX = (2.0f * isometricY + isometricX) * 0.5f; float cartesianY = ...


1

Use Array (or regular java [] array!) (Ground[] grounds = initialize all;) with index that points to the first visible Ground in that array (int first = 0;). Keep some counter (float x = 0;) which will hold progress to the next index. void update(float delta) { x += delta * speed; if(x > groundWidth){ x -= groundWidth; ...


0

It looks like you are trying to put these actions in a SequenceAction, put both move and alpha action into a ParallelAction which then put into your sequence. actor.addAction(Actions.sequence(Actions.parallel(moveAction,alphaAction), moreActionsInSequence)); Also consider using VisibleAction (Actions.show/hide/visible) instead of alpha 0 for hiding ...


0

You are most certainly trying to use your shader in SpriteBatch. SpriteBatch is setting up the shader's projection matrices, which are by convention (as MadEqua answered) called u_projTrans, not u_projectionViewMatrix (see SpriteBatch source). SpriteBatch also uses some more uniforms which you must declare (and use, so they aren't optimized away). However, ...


0

This is a broad question because there is no "best" way, but a good way to do it, if you're using Scene2D (which I highly recommend if you're making anything that is 2D) is to create a new Actor every time damage is done and add it to the stage. The actor should probably extend Label and upon creation add Actions to itself that cause it to rise and then fade ...


2

This is due to either a context loss or simply you disposing your textures, without recreating them at the proper time (as you pointed out).


0

Wow wow wow. So clear() removes all children, actions, and listeners... All I needed to change was clear() to clearChildren()...


0

Why not just set the VSync to on at the start of your game and create a variable within your code that will store the VSync boolean. Then if a user changes their VSync settings you update your variable as well. This will also allow you to save a user's VSync option because you can store your boolean when the game exits and when it restarts, set VSync to the ...


1

Idea behind screens, is to separate logic between different context. However, those screens can still share data and have references to some classes that were originally initialized at original game class. If you don't use screens, you will have to dump all the code to main game class. Even if you try to hide logic behind different classes, you still end up ...


0

Your application is trying to find an uniform in the shader called u_projTrans to send it the projection matrix. The simplest fix is changing this shader line: "uniform mat4 u_projectionViewMatrix;\n"+ to "uniform mat4 u_projTrans;\n"+ Then the variable names should match on both the application and shader sides.


0

You can use Game for everything you like. Game is just class that implements ApplicationListener and supports screen switching, nothing more. So design you code as you wish. Just be sure that your Game class doesn't become dump.


0

There is nothing wrong with the shaders. The error you're getting is due to somewhere in your program your calling a line similar to this: shader.setUniformMatrix("u_projTrans", matrix); Basically this error is thrown when either u_projTrans doesn't exist in that shader or it does exist in the shader but you don't use it. When it's not used the shader ...


0

Don't use a variable time step for physics, this will mess up the entire engine. Box2D will attempt to apply enough force depending on the level of penetration, if the step is constantly changing then Box2D is getting different numbers each time it tries to separate fixtures. Use an fixed timestep instead: world.step(1f/60f, 5, 8); Or some other ...


2

First your use of the aspect ratio is nonsense. The aspect ratio is the relation of width to height. So if you have float aspectRatio = (float)myGameHeight / (float) myGameWidth; This means that the the following is true: myGameHeight == aspectRatio * myGameWidth If you want to preserve the aspect ratio of the screen you need to do the following: ...


0

Found the problem: Stage and Spritebatch needs to be initialized in the show-method (in both of the above methods). From this: public class MainMenuScreen implements Screen{ SpriteBatch batch = new SpriteBatch(); Stage stage = new Stage(); public void show() { Gdx.input.setInputProcessor(stage); } to this: public class ...


0

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


0

Just had a similar problem. The following code in the render method of the screen helped: stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));


0

Try only updating the state time of the animation when the condition is true, and then when it goes from false to true and the animation needs to re-start, set the state time to 0 again. float stateTime; void render() { if(condition) { stateTime += Gdx.graphics.getDeltaTime(); } frame = animation.getKeyFrame(stateTime, true); } void ...


0

Try using vector math instead of cos/sin angles. Something like this might work for you; public void moveAlien() { float velocity = 50; Vector2 ap = new Vector2(AlienBody.getPosition()); Vector2 mp = new Vector2(Marinebody.getPosition()); Vector2 delta = mp.sub(ap).nor(); // This is not a unit vector pointing in the direction from ap to mp ...


0

You could move the background or make a new orthographic camera. Then do some thing like camera.setPosition(player.x, player.y);


0

I'm no too sure of the overall design of your game, but I don't see why you would need GameWorld or GameRenderer classes since Screens generally accomplish such tasks. To separate the player and keep collision detection you can simply require the instance as an argument: private void checkCollisions(Player player) { for (Drops e : getDrops()) { ...


0

LibGdx is taking care of the FPS itself, there's no need to for you to intervene. remove all the fixing methods, your delta time is now - gdx.graphics.getDeltaTime() use only it (send it to world.step())


0

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


2

After days of stress, I've finally fixed the problem. After performing a backtrace on the main thread I discovered the program came to a halt when trying to load the Google Analytics trackers. This is the thread backtrace: at com.google.android.gms.analytics.ae.getLogger(Unknown Source) at com.google.android.gms.analytics.ae.W(Unknown Source) at ...


1

Calculating the vector that points from a spring at point A = (x0, y0) to a spring at point B = (x1, y1) is simply: v = (x1 - x0, y1 - y0) Assuming no other forces acting on the player, then changing the player's velocity to some scalar multiple of v when they hit spring A would direct them to spring B. If another force like gravity is involved, then, ...


0

I found an answer on Stack Overflow. The thing is I had to call layout() on the scrollPane manually. The reason: Because the height of a wrapped label is unknown until layout() is automaticaly called while drawing. The maximum Y scroll position remains the same until this happens.


0

Stop using pixels and use virtual units. Remember that if you don't have camera.unproject(); in your input processing code then you have bad input processing code.


0

Moving background has better performance than moving camera. On the other hand, moving camera is more intuitive and that's what we see in real life.It's all up to you.


0

once there's a valid screen loaded Gdx.graphics must have a valid width and height defined, i think you're just asking for something null that's not related i.e. float[] size; size[0] = Gdx.graphics.getWidth(); ... which it will give you a nice NPE


1

The issue is the else condition after you check the A and D keys, since if no key is pressed it will reset the direction to 0, 0 every time the update() method is called. Instead of calling moveLeft() and moveRight() in the touchDown and touchUp you should keep track of each pointer passed by the touchDown and touchUp methods and check whether the pointers ...


0

A much better option is to create a small class (or reuse a suitable one like Rectangle) and keep them in a list, the code becomes simpler and it will be easy to add more buttons over time. InputProcessor inputProcessor = new InputProcessor() { private final static List<Button> buttons = ... private Button lastButton = null; abstract class ...


0

I'm just getting into libgdx/scene2dui as well, but maybe I can offer some help. I found using tables quite handy and accurate. It also has the benefit of relative positioning of objects. I don't know about CSS, but why would you use absolute positioning, it screws up if you want the game to be playable in different resoultions and aspect ratios and makes ...


1

If you're also working with box2D, you could try box2Dlights, it's a pretty nice wrapper and it's easy to implement as well.


1

There are ways to do dynamic lighting without shaders, although they're usually not as efficient. They often involve raycasting. The link below has some links to useful resources regarding dynamic lighting. http://www.java-gaming.org/topics/2d-dynamic-lighting/27012/view.html



Top 50 recent answers are included