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


4

Mathematically speaking, a distance is a value which is never lower than 0. You can see this thing in your getDistance() function implementation: the argument passed to the square root function is a sum between powers of 2. A power of 2 is always positive, their sum is positive as well, and the sqrt() function will always give back a positive value. So, no ...


2

More code would be helpful, but you likely need to put this in your show method. public void show() { Gdx.input.setInputProcessor(yourInputProcessor); // This should keep it from exiting. Gdx.input.setCatchBackKey(true); ... }


2

Your best bet is to make a class that replicates Javas Graphics class in LWJGL. For textures you can write your own LWJGL wrapper or use Slick 2D


1

How about changing your approach to the simpler solution? You could just manually rotate the sprite in your update-method with something like the following: sprite.setRotation((sprite.getRotation() + rotationSpeed) % 360);. That way the sprite will smoothly spin around forever, and your code stays clean and straight-forward.


1

The best way to load in music and sound effects resources is through LibGDX's audio methods: Music music = Gdx.audio.newMusic(Gdx.files.internal(path_to_music_file)); Sound sound = Gdx.audio.newSound(Gdx.files.internal(path_to_sound_file)); To play the music: music.setVolume(1f); music.play(); To play the sound effect: long id = sound.play(); sound....


1

You should avoid invoking new instances in your render and update methods. As these methods are called numerous times per second, this can be a pretty straining task, as the unreferenced instances will have to be freed in memory through garbage collection. To solve the two Vector2 problems, easy: Declare and instantiate two global Vector2 attributes, and ...


1

It is a little bit difficult understanding your question, but I think your problem is caused by the fact that you update all ballons in the update (float dt) method even though you're not drawing them. This means that when 200 iterations has passed and you draw ballons and ballons2 for the first time, they have already moved some distance.


1

The algorithm you are using right now has a runtime of O( n^2 ). A tree structures can help you get that runtime lowered. Quadtrees have O( log(n) ) From that you can calculate if you will benefit from a quadtree.


1

in your update method you should add the below code. if (Gdx.input.isKeyPressed(Keys.BACK)) { game.setScreen(new MenuScreen(game)); } // and in your game Screen classes show method Add this code Gdx.input.setCatchBackKey(true);


1

The problem is in your game loop You are limiting your rendering fps to your game world fps. You should update your world on a fixed timestep and either leave the render timestep to vsync or limit to something like 60.. You're using non floating point variable types where you should be using floating point math. This adds imprecision and can cause ...


1

Shadow and Ball are key aspects. Shadow size and distence between Ball and shadow should increase when height increase. Also, Ball size should increase when Ball height increase. Shadow position represents position of ball in 2d and when Ball height increase you have to change Ball position (I m assuming that light source is homogen and it is not single ...


1

Brief: The solution is not in collision listeners, but in collision filters. Collision filters have a shouldCollide method that you can implement to return false if you want to disable collision or true to allow it. Collision filters are executed before collision listeners. You can use, for example the linear velocity of the player sprite to decide if you ...


1

You need to learn a little bit more about vectors but I'm going to explain it anyways. First of all, let's say that your 'game unit' is in pixels and that points (coordinates) and vectors have two components x and y. Let's assume that you have two given points A = (x1, y1) and B = (x2, y2). To get the vector between A and B, you have to do the following ...


1

Threads would definitely be overkill here. I would use event listeners. First, make an ICommand interface. (The param is so that you can optionally pass data to your command) public interface ICommand{ public void execute(Object param); } Then make sure you clearly define every scenario in which a card will activate and create a ICommand variable in ...


1

Your primary question is: So how do I implement the force? Considering that your body is always underwater, there's an easy way out of this one: just use gravity :) As iforce2d points out in his tutorial on custom gravity, you can set the gravity scale of any object: //Box2D v2.2.1 onwards body->SetGravityScale(0);//cancel gravity (use -1 to ...



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