New answers tagged

0

You can assign a listener to each of these cards if they are actors. You can create and enum with each card: public enum Cards{ ACE_HEART("ACE_HEART.png"), 2_HEART("2_HEART.png"), 3_HEART("3_HEART.png"); //etc private final String name; Cards(String name) { this.name = name; } public int getValue() { return name; } } and ...


0

Take a look at Viewports. Many of the Viewport subclasses take virtual height and width in their constructors. There are different flavors of viewport depending on how well you want Libgdx to keep to your desired aspect ratio.


0

Calling invalidate(); inside the DoteView.delete method which tells the view to redraw itself does what I want. Public void delete(){ mPaint.setColor(Color.TRANSPARENT); invalidate(); }


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.


0

€dit because my previous answer was not the correct one: First guess: the region is too small, or whatever he can't process the image. I would debug into the draw method and look, if the table actually has a background in the draw method, because if no background is there, the method just draws nothing.


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

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

It seems that if the VerticalGroup is added to another layout, then it works. Looking at the code, this is due to VerticalGroup also being a Layout, and so it's prefWidth/Height are used instead of the getWidth/Height methods. I got around this by manually setting the size to the pref. size. setSize(getPrefWidth(), getPrefHeight()); Note, that you don't ...


-2

A grid. Implementation is more simple and often times superior in performance. Edit: Hu, why the downvotes? This was more of a follow up info to the accepted answer. The OP asked for alternatives. You can find grid vs. quadtree discussions everywhere. Bottom line is a quadtree doesn't deliver a better performance (often times it's slower) than a simple grid ...


0

The problem is that your update function is only fixing the position of the balloons to the Box2D body. Since the Box2D body is created and added to the world on creation, the body will still be moving even though it is not drawn. You can disable the balloon's bodies until they are ready to be drawn, like so: Balloons.java public void defineCollector(...


0

No, you don't have to keep seperate assetmanager for different game states . One Assetmanager is enough for all the states. Moreover adding multiple Assetmanager leads to increase the load of GPU. Which will effect your Game play. So better use only one Assetmanager to load the all Assets. And Assetmanager is one of the class which should be disposed ...


-1

Just do one thing you can change the method which your following now. you can use the "hiero" tool for the font creation . Just download "hiero" jar file from the following link https://libgdx.badlogicgames.com/tools.html by using hiero you will be able to access almost all the fonts . after creating the fonts save it on your android project files "asset" ...


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


0

texture = new Texture( Gdx.files.internal("Menubckgrnd/MenuScreen.png")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); // here 2048 and 1238 is the actul width and height of the image . so replace these values with your images height and width TextureRegion region = new TextureRegion(texture, 0, 0, 2048, 1238); ...


1

If you want to setup a physics data for an object that is already on the screen, just right-click on it and select “Edit Physics” button from drop down menu, this will bring up the “Edit Physics” dialog. There you can choose if your object is static or dynamic, set its mass, friction, density and so on, and draw the polygon mesh for its fixture shape. ...


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.


0

Each time you put your fingers on the screen the originalDistance / currentDistance will result in the value 1. If you use this value directly the zoom would always start at zoom = 1.0f. To solve this issue you should store the current zoom factor at the start of the zoom and multiply this with the new calculated ratio. So: on touchDown take the current ...


0

You can solve it easy by making additional rectangle above the rectangle attached with it, and respond differently for each rectangle, by this way you can control the collision


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.


0

You should use your ShapeRenderer as an input into your draw function. // The shapeRenderer as input public void draw (ShapeRenderer renderer) { renderer.set(ShapeType.Filled); renderer.drawRect(this.xcord, this.ycord, this.width, this.height); } Taking the ShapeRenderer as input also allows you to iterate over a list of rectangles to draw your ...


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


0

Turns out the answer has to do with alpha channels and the way they were being processed. I removed transparent pixels from the edges and it works as intended now.


0

This may be the same problem as this question on SO (haven't used TextureAtlas before so not entirely sure)


0

I don't know if the method you posted is called every frame, but (Hud.getTime()==0&& Hud.getScore()<(level*15)+50) will always be true once the time is up. (thus giving that linear impulse and starting the sound every frame). I would try to nullate the score.


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


0

Just do one thing you can change the method which your following now. you can use the "hiero" tool for the font creation . Just download "hiero" jar file from the following link https://libgdx.badlogicgames.com/tools.html by using hiero you will be able to access almost all the fonts . after creating the fonts save it on your android project files "asset" ...


0

Libgdx provides Texture and TextureRegion classes that should do what you need. A Texture is a handle to the entire image. One way to load it is Texture dogTexture = new Texture(Gdx.files.internal("path/to/dog.png")); and a Texture is drawn using a Batch //x,y,width and height are where and how big the texture is drawn in your world batch.draw(...


0

The issue is probably because of Texture Filters. And it's not LibGdx problem either, but OpenGL's. You can set filters for Libgdx textures using setFilter() method. For eg., try setting the filter to: yourTexture.setFilter(TextureFilter.MipMapLinearNearest,TextureFilter.Nearest); Here's the detailed explanation written by Mario himself.


1

Try changing the image using setDrawable() method: loading.setDrawable(new TextureRegionDrawable(new TextureRegion(new Texture("90.png")));


0

Do you have called that in your render method: Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Because, it looks like your code should work. We figured out, that he needed to disable, because he wanted to draw the Screen on demand "continuus rendering" https://github.com/libgdx/libgdx/wiki/Continuous-%26-non-continuous-rendering


1

You missuse the animation class. you need to do the following: currentframe = animation.getKeyFrame(Gdx.graphics.getDeltaTime(), true); Currently you use an increasing time for your time passed. which is wrong, the animation class handles the passed time by itself. Easier explained: Imagine a cake. If you eat constantly 3 percent you'll see it fade ...


0

I think that the most simple way of getting around your problem is as follows. I assume that your player entity helps you keep track of his state. Maybe it's running, or climbing or whatever you might have used. If you add to make sure that the only time you will ever check if the player sprite is on top of an enemy is when the player's state is falling, ...


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


0

Creating only one is probably better. If you have one object storing and managing the lifetime of assets that you share between all levels, that makes it trivial to share assets across each level (for example, common, always-loaded assets). If you have one asset storage object per level, that does not naturally lend itself to sharing common assets (you ...


0

I would do what the above posters suggested, Shadow and size increase when ball is higher. A thing I remember from playing tennis on old TV games is that the ball also slowed down the higher it went and bigger it became. When it reached it's zenith and started "coming down" it would start going faster again as it became smaller.


0

The fixture position in box2d is in relation to the body position. So if you set your fixture to be at (5, 5) the body is still at (0, 0) and if you then move the body to (1, 0), the fixture will then draw at (6, 5). It looks like you are getting your sprite position from the Body position, not the fixture position in the original method. In the second one,...


0

I'd suggest you give your actor (I suppose you use Scene2D) a bigger size, than your Image. If you dont use Scene2D I recommend that you watch into it, because that would is the best way I can imagine to do such a game. But as a final answer on your question: add transparency to your Image at the border. (which would go quite easy for once, but changing it ...


0

I fixed it by changing the main update loop and i followed this ordrer Input Physics (World & Bodies) Camera (position & update) Graphics Box2D Renderer (if neeeded)


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


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


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


-1

You draw a shadow below the ball, like it's done in the gif. The higher the ball, the longer the distance between the ball and the shadow.


0

Here's the documentation on the type Vector2 in libGDX. https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Vector2.html From this I can guess that code you could use would be something like this: //Setup the positions of the player and the target position Vector2 targetPos = new Vector2(Gdx.input.getX(), Gdx.input.getY()); Vector2 ...


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


0

To get from point A to point B where both A and B are vectors, the direction is the vector normalize(B - A), lets call it C. The velocity you're looking for is the direction-vector C times the speed in units per second. So if A is your actual position, B is your target position, 10 is the speed in units per second and delta is your deltatime, then your ...


0

To achieve the water reflection and shimmering effects, you need to work with two sprite properties only: alpha level, and width scale. Alpha level: the reflection on the water surface shouldn't be opaque, like on a perfectly clean mirror. You can use sprite.setAlpha(float a) with a value between 0.5 and 0.8 (in my opinion) to get a semi-transparent ...



Top 50 recent answers are included