New answers tagged

0

The problem with your code is here: @Override public boolean keyUp(int keycode) { switch (keycode) { case Keys.W: //when W is released, set Y velocity to 0 velocity.y = 0; break; case Keys.A: case Keys.D: velocity.x = 0; break; } return true; } While canJump is a boolean that checks if the character has jumped, I assume you want the ...


0

It looks like your problem could be that your MyActor class does not report it's width and height to the parent Actor. Just because you have an Actor that has some other Actors as members doesn't mean the "parent" Actor will know how tall and wide it should be to accommodate all of them. By querying the preferred size of the child Actors you can return more ...


0

One way of doing this that's quite easy is to let there be a single class that extends Game, that launches the first Screen (this is pretty much what you have). What you also need to do though is to pass a reference to that Game to all your Screens so that they can call setScreen themselves when they want to go to another screen. In a somewhat simplified ...


0

Clearing out the IntelliJ project and files and re-importing from the gradle.build solved the problem. IntelliJ must have been caching something somewhere.


0

So after reading more into how .tmx files are read I was able to fix my problem. Here is how to properly do it when working with multiple tilesets and re-packing your spritesheets in TexturePacker. First, cut up the tileset images using a utility like ImageMagick and make sure they are indexed (specified by an underscore and number in the filename). You can ...


0

If the rectangle is only going to rotate 90 degrees at a time, then the simplest possible way of determining whether a ball is colliding with a black side or not is to have a rotational state of the rectangle, for example, a simple integer: int rotation_state = 0; // 0, 1, 2, 3 defines four rotational states, 0 is up Let's say a ball's spawn position ...


-1

Are you talking about the editor tiled? Because in that you can add any number of tilesets.


0

LibGDX has an AndroidLauncher file that's located in the Android java folder that opens up the game file in the core folder but you have to add it to the android manifest for it to work


1

You can call the createBalls at some interval from your game loop, and possibly pass in how many balls you want it to create. For example; public class YourGame extends Game { private long lastTime; @Override public void create() { } @Override public void render() { if (TimeUtils.nanoTime() - lastTime; > ...


2

Cursory answer: "it might be". If you are doing "carpet testing" for collision detection, no offence, but you are doing it wrong (unless you have very few elements to test): pair checking of any kind is a O(n^2) operation, and will start to eat at your cpu time very fast as the number of objects you have in the game increases, so you might want to improve ...


0

the steps to do this are: generate a list of N random heights int h[]; generate a list of N-1 distances where distance is the difference between the 2 heights dist=abs(h[i] - h[1]) use this information do draw your line segments with the desired amount of noise where the number of segments between points is <= distance. this will ensure that the ...


1

It's a bit vague what you want to do and what you have. But this should help: Vector3 pos = new Vector3(); Matrix4 nodeTransform = new Matrix4(); nodeTransform.setToTranslation(2, 4, 0).rotate(Vector3.Z, 180f); nodeTransform.getTranslation(pos); Gdx.app.log("Node pos", pos.toString()); Matrix4 modelTransform = new Matrix4(); ...


0

If you know the boundingbox size (you should), the character position would be: character.y=floorBoundingBox.y - characterBoundingBox.height You don't actually directly calculate the difference between the floor and the character, you calculate the position of colliding objects by pushing them their height or width outside the floor.


0

If it's the allocation of the Vector3 you're worried about you might consider keeping an instance as a private member of the class and re-use that; private final Vector3 v3 = new Vector3(); public void yourMethod() { if(cam.frustum.pointInFrustum(v3.set((float)posX, (float)posY, 0))) { } } Another way, if you have many of these instances you could ...


0

Take a look as using a different type of ViewPort (this page shows the different types). Based on what you have described I would recommend using a StretchViewport, which would upscale (or downscale) your 480x320 camera to whatever resolution you needed it to be. Note that if you changed the aspect ratio you might get some ugly stretching artefacts.


0

I have done it like this: First i have created a new Class called Hud. It implements Disposable because of the resource management. Then you need to define a Stage for your content and a new viewport because a new camera will be used. You need to define a new Tablethat you can add to the Stage. You can add your content to the table like usual. The rest of ...


1

Create the menu in one Activity, and let that Activity be a "normal" Android activity, then have that Activity launch the libGDX game Activity. That sort of approach would allow you to use Android layouts for the menu but libGDX for the actual game.


1

I think you mean just the look of the button? You need to do that in your favorite bitmap or vector app like Photoshop, Paint.net, Graphicsgale, etc. Search something like glossy button tutorial to learn how to make a nice looking button. Make a up, down and disabled state if you desire and set them as drawables to the corresponding "slots" for the button. ...


1

Do not just set font and fontColor, also set the properties that make up the vidual appearance such as up, down and checked etc. They take Drawable and will allow you to use any image to represent your button.


0

I had the same Problem with my game and i watch a tutorial series on youtube from Brent Aureli. He is explaining this really well i will put a link right here. Maybe it will help you as well . https://www.youtube.com/watch?v=tcH6Mp03KC0 Edit: Have you set the CategoryBits? like that public static final short NOTHING_BIT = 0; public static final short ...


0

You can use the filter on the FixtureDefinitions to define what type of objects can collide with what. You define a category bit-pattern, this describes what the fixture is. Then you define a set of categories that the fixture collides with. For example; class PhysicsConstants { // Categories public static final int CAT_SHIP = 1; public static ...


0

You have to check if the distance travelled is greater than what remains to travel; if it is, you arrive at your destination on that frame, explicitly set the position instead of 'travelling': public void Draw(SpriteBatch batch, int goalX, int goalY){ destX = goalX - posX; destY = goalY - posY; dist = Math.sqrt(destX * destX + destY * destY); ...


0

Short answer: public void update() { if (Gdx.input.justTouched()) { //Touched left side of screen if (Gdx.input.getX() > Gdx.graphics.getWidth() / 2) { //give actor upforce and and a bit of force to the left someActor.setVelocity(new Vector2(-25, 100)); } //touched right side of ...


0

The solution is simple as that: P = Circle center r = radius or the circle You get the closest point from the circle center to the polygon (C) (I assume you got that already) Get the distance from the closest point to the circle center (D) = C-P Normalize that distance to get the unit vector (N) Get the signed distance to the edge/vertex and take the ...


0

So if I understood, you want to get the cell that is clicked so you can color it. private void fillTouchedCell() { if (Gdx.input.isTouched()) { Cell c = getCellAtTouch(); if (c != null) { //cell clicked, we cant fill it with color c.fill(Color.RED); } } } private Cell getCellAtTouch() { unpojectedTouch.set(Gdx.input.getX(), ...


3

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


0

Try setting the position on the FixtureDef. I'll assume that you already converted the units to Box2d: public static Body createCarBody(Vector2 position, float sizeX, float sizeY, float density, float friction, float restitution, float linearDamping, float angularDamping){ System.out.println("position createCarBody " + position); Body body = ...


0

Instead of applying the position to the Shape if the FixtureDef, apply the position to the Body. Something like this might work for you; public static Body createCarBody(Vector2 position, float sizeX, float sizeY, float density, float friction, float restitution, float linearDamping, float angularDamping) { System.out.println("position createCarBody " ...


0

Ok this is how i would do it. public void handleInput () { mouse_x = Gdx.input.getX(); mouse_y = Gdx.input.getY(); rou_mouse = new Vector2(mouse_x/cellWidth, mouse_y/cellHeight); set_px (rou_mouse, new Element_stone()); } The new vector2 arguments should give what cell number ...


0

You can use setAngularVelocity(float omega) LIBGDX API for angularVelocity


0

You can use the delta variable of the render() function. This variable is a float value of the time elapsed since last render call (Something like time from frame to frame, not exactly, but this is the idea). Simply add the delta time value to a variable and then execute the code you want when the variable gets to a specific (or random number). Generic ...


0

Your code is a little bit confuse. Also, I tried cloning it and the project is incomplete, so I can't import it. If I understood your code, you're using box2d bodies but you're not setting the sprite position taking in consideration the Box2d units. Box2d works with meters, so you have to convert pixels to meters and take in consideration the fact that box2d ...


0

The way I do it is, first the shapeRenderer (begin-end), and then the batcher (begin-end). I'm assuming you're begining the batcher before the shapeRenderer. I think I read somewhere that can cause trouble. Example: shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.setColor(80 / 255.0f, 80 / 255.0f, 50 / 255.0f, 1); ...


1

One way to do this would be to clamp (limit) the x and y values of the camera to your width and height of the game. It may look something like this: Clamp method: public int clamp(int var, int max, int min) { if(var > min) { if(var < max) { return var; } else return max; } else return min; /* * var = your variable ...


0

Incidentally, I have done exactly what you are trying to do. The only catch is I was using Jbox2d so the code is in Java, but you should still be able to figure it out if you are using C++ You basically need to use joints/motors and all that fun stuff if you want to do swinging action. Here's a snippet of what my code looks like based on the key input: ...


0

I had made a game similar to yours with almost similar logic ,I had moved camera,instead of moving each element individually as moving camera is easier and saves lot of logic's. I had a class cameraHelper that gets and sets all necessary details about camera import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.math.Vector3; public ...


0

Yes, if there's extra data/rendering being performed that's outside the bounds (frustum) of your camera, it would be more efficient to not attempt to render the geometry that can't be seen. How you actually do this depends on how your game is structured - tile-based 2D games can simply figure out what bounds of the world to draw, whereas 2D and 3D games not ...


0

Since you're not strictely looking for code-based answers you might want to try: Of course assuming it doesn't constrict your level design. (Skitskraj's answer is pretty good too tho)


2

As suggested in the comments, you should try to use Tri-Linear filtering and MipMaps. The reason using TextureFilter.MipMapLinearLinear results in a black box is that you haven't generated the texture with MipMaps. In order to do so, simply pass a second parameter to the Texture constructor as true like so: img = new Texture("circle.png", true);


0

I found out that it was a lack of memory that helped me to open the picture.


0

I am not sure what you mean with Sensor Listener, but In case you mean accelerometer and other mobile phone sensonrs. You can disable them with this code: AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); config.useAccelerometer=false; config.useCompass=false; initialize(new yourGame(), config); More information on the LibGDX ...


2

You shouldn't call dispose directly on a Texture loaded by an AssetManager, they are disposed the the AssetManager is cleared or disposed or if you call unload on the AssetManager and pass the Texture. The reason you shouldn't dispose assets from an AssetManager is that they can be shared between many other assets (two fonts may use the same texture for ...


2

If I understand the problem correctly, you were close to properly solving it. Your approach with the normals is what you want, but instead of only saving the normal of the last collision, save a list of normals from all current collisions/overlappings. Then, play the sound whenever the new normal of the new collision is not yet present in the list. In ...


1

Ok, I'm piggy-backing on Skitskraj's answer here so if you like mine, upvote his/hers too. Solution: Play the sound only if there is a new contact and there is a significant velocity change. I would suggest using the postSolve callback on the first iteration of the collision to determine if the impulse is above some threshold value required to generate the ...


1

I reccomend you delete and load smaller pieces (~50m) at a time to keep a more stable (if not lower) fps.


3

I don't think you can fix that "loading" issue, if your game has to open a file from HDD, load the content, parse it and draw it there's nothing to do that could speed it up. I would say that, the best you can do is store the whole map in memory and get chunks more often, like 100m sou you should be able to high speed reading from ram and the lag would ...


2

You can find all what you need here Tile maps class, and read the section Rendering Tiled Maps according to Libgdx docs: Performance considerations While we try to make the renderers as fast as possible, there are a few things you can consider to boost rendering performance. Only use tiles from a single tile set in a layer. This will reduce ...


1

From you code I can't tell what the ownerv vector is so I can't tell you why it's giving you the wrong result. But to do it from scratch, according to Wikipedia's article on vector projection, you can do the following; Create a vector a that is the direction from o to v. Create a vector b that is the direction from o to n. Let d be the dot product of a ...


3

The texture regions inside don't need to be powers of two. But texture compression cells are often 4x4 so you have to be careful when using compressed textures that the edges of two texture regions don't share the same cell or they'll be compressed together which will degrade the quality if they have different colors. You should leave a N pixel border ...


0

If you are familiar with Android's UI design, and its properties, it is pretty easy to program something for yourself. So if you want to learn to design a pretty UI, study Android. It doesn't matter game UI or not. It's same thing. I recently made a ListView. I haven't tried it yet. So it is incomplete. But there is some rules, every UI element should obey. ...



Top 50 recent answers are included