Tag Info

Hot answers tagged

5

Disclaimer: I have not used libgdx or Java before, this answer borrows syntax from the question and official documentation, and the code is untested To make the bodies 'fall' under the influence of gravity in box2d, you must first pass a non-zero gravity vector to the b2World when constructing the world World world = new World(new Vector2(0, -10), true); ...


5

It defaults to locked on "landscape" mode in a libGDX project. You need to go into your "AndroidManifest.xml" and change android:screenOrientation="landscape" too android:screenOrientation="sensorLandscape" There are more options - http://developer.android.com/guide/topics/manifest/activity-element.html#screen Just replace "sensorLandScape" with the one you ...


4

The particles themselves associated with a particular effect shouldn't be tied directly to the object. While there is never a 100% use-case scenario, this still applies to most situations. Your object itself shouldn't be managing the life-cycle of a particle effect, though it may be the instigator for spawning particular effects in the world. So, in your ...


3

Simple Solution If you want the body to instantly rotate just call Body::setTransform and pass the current position and the desired angle, don't bother applying torques or anything. The function call could be something like this: body.setTransform(body.getPosition(),myDesiredAngle); Physics Solution If you want the player body to interact with bodies ...


3

Gdx.file.internal is read-only. You can use local file or preferences (creates an internal .xml file where you can store small amount of data). It is perfect for game saving. Take a look at : https://github.com/libgdx/libgdx/wiki/Preferences You can also use an external file (stored on sdcard), but you can optionally encrypt it, as it can be edited by the ...


2

Read the wiki! Controllers connects/disconnects don't give listener events (right now), so controllers must be polled manually. The wiki says controller listeners don't work on the desktop for connects or disconnects. I'm no expert, I've just been reading the wiki in detail, but it looks to me like you must poll the controllers manually. This code will ...


2

You could change the color of the sprite batch when it is drawing the bullet, and then back to white, like this: public void render(float delta) { batch.begin(); // some rendering worldRenderer.renderBullets(batch); // some other rendering batch.end(); } And, in renderBullets() of the world renderer you do the following: public void ...


1

Keep rendering the game. just pause the logic! You can esily just attach a "pause" pass, that will render the framebuffer and then blur it or what not, and after that add some gui! should be really straight forward. The only reason i can imagine why you would like to take a screenshot is to not use all the gpu power and reduce lag when you are pausing. ...


1

Why don't you create a class for your coin object, and then collect all the coins in an array (Sprite[] coin), so whenever a collision occurs (player-coin), you call coins[i].destroy, where you can properly dispose all the referenced resources, or reset position for the next coin ? For drawing : for (int i = 0; i <= quantity of coins; i++) { ...


1

Thanks for the comments -- I finally understand what you want. TLDR: the summary of your question is encapsulated in the libGDX project setup page. Essentially, libGDX has you create one "core" project (which is a standard Java project). Within it, you have your main game code. Beyond that, you have wrapper projects (one per platform); these only call the ...


1

Sure. Take your camera matrix and unproject it (or invert it). This can be done in libgdx like so: Vector3 worldCoordinates = new Vector3(screenX, screenY, 0); camera.unproject(worldCoordinates); The documenation can be found here.


1

What your dealing with is an aspect ratio mismatch. Your trying to map an aspect ratio of 1 to an aspect ratio of 16:9 or 16 :10. That is why your tiles look stretched. Set your games resolution to a square aspect ratio like 300x300 if windowed. Or make your tiles about 160x90 pixels to look square at that resolution. Topics of interest would be ...


1

You should probably use texture regions. With texture regions you can select a sprite, doesn't necessarily have to be a sprite in your case, and slice it up in parts to be reused. As example: int numOfTiles_Horizontal = 3;//Can be any size as long as it lines up with the texture size. int numOfTiles_Vertical = 3;//Can be any size as long as it lines up ...


1

Trust me look into Scene2D. It handles everything input related for you. You can even do timed based actions on it, which are very nice. Its also built into libGDX. Truuuuust me its super easy once you get the hang of it. Honestly, I now write everything in Scene2D. If your having issues getting started with it, Heres a little sample code for you Stage ...


1

Bodies are made up of one or more fixtures and fixtures define a shape. This means, for each fixture, you need to get the shape and its size, then combine those to get the total width and height. It looks like the easiest way is with getRadius(), but that doesn't give you much. You may want to get the shape type, then create methods for getting more detailed ...


1

I finally got it !! package com.Main; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GLCommon; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import ...


1

Your solution is probably the easiest way to do it and I see no reason of why it wouldn't be valid. If you use only one sprite for a character this will mean that you will have to do a sprite per walking-direction/firing-direction combination pair. In the case of a character viewed from the side you can use deformation to deform the sprite in the correct ...


1

For minimizing the amount of black bars you should aim around the median ratio of target devices, that would probably be 8:5 or 5:3. But if you really need your game to be a fixed ratio, consider using some filler art instead of black bars, you might simply have a playing field background with some out of bounds area that is cropped away depending on screen ...


1

I couldn't find any help with my issue so I resorted to adding multiple Labels and using the Label's X, Y, width and height to set the position of the Sprite. I also require an animation which I don't think is possible in a Table, so I will have to just do this. Thanks for your help.


1

Unsure if you found an answer, but for anyone else who came here looking for one: Setting Gdx.input.setInputProcessor(stage) basically means the stage is getting all input signals. So to get your events to fire, you need to change buttonPlay.addListener(new InputListener() to stage.addListener(new InputListener() and do that for the rest of your ...



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