Tag Info

New answers tagged

0

I solved it! Here is the process I followed: Render Lower Tiled Map Layers Render Entities Render Upper Tiled Map Layers Render Upper Tiled Map Layers to stencil buffer Render Entities using the stencil buffer with a simple color fragment shader The code. Rendering the upper map layer: // Render the top map layer normally renderer.render(layerIndeces); ...


0

I guess you are looking for the constructor: GestureDetector(float halfTapSquareSize, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener) The default constructor has this values: halfTapSquareSize=20, tapCountInterval=0.4f, longPressDuration=1.1f, maxFlingDelay=0.15f. I don't ...


0

As @drumbumLOLcatz says, there are a bunch of overloaded methods when you create your shapes, what you are looking are for those methods that involve a degreeparameter. Something like this: public void rect(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float degrees) So everytime ...


0

If you are creating a 2D game with tiles you can easily implement your own culling which is a lot cheaper since you only itterate over exactly what you need within your tile array. Things you should know: Camera location Viewport width/height Tile width/height Now we can calculate how many tiles should be drawn. Total horizontal tiles on screen = ...


0

According to the source history on Actor , the hasActions method was added 7 days ago. Get latest and I think it should work for you.


0

For many collisions, there will be several contacts to resolve. This is why you're getting multiple calls to your player.destroy(). I don't know what you're doing in the destroy method, but you shouldn't destroy any Box2D bodies of fixtures in there, as they might be needed for other preSolve calls. What you could do is instead of immediately destroying ...


1

I don't think this is possible in your case. A repeating texture at the hardware level needs to span the entire texture, at least on the axis it is repeating. You can still repeat the sprite if you write your own routine. You would just call draw() multiple times. If you decide to load your repeating sprite as a separate texture so you can render it in one ...


4

The problem you are facing is conversion between two different coordinates systems: the graphical one and the input one. Graphics coordinates Like you said, libGDX uses a 1 to 1 ratio between space coordinates and pixels, and starts in the bottom left corner. But it can be anything, really. That is just the default behavior of libGDX. You could change the ...


0

I suggest to create a "CharacterReflection" object in your game that updates his sprite and position based on the character's current sprite and position, and is drawn only if character is above water. I mean, in every update() call of this new object, you set the sprite to be the copy of the character's sprite and then reflect it on Y axis. The reflection ...


0

Firstly, your question is very unclear. It doesn't have all the necessary information. Nothing at all in fact. Try to be a little more informative or precise in the future. When two bodies collide in Box2D there are numerous collisions. Collisions in Box2D are really the fixtures which are used to detect when a collision occurs. Collisions can happen in ...


0

So I finally found a method on some Github repository (I can't find the link again), and this one actually works. It doesn't use matrices and it doesn't to measure the screen or any of that crap. private Vector3 worldToIso(Vector3 point, int tileWidth, int tileHeight) { gameCamera.unproject(point); point.x /= tileWidth; point.y = (point.y - ...


0

ideally, you configure group/mask for your lights and objects. Using this, you can tell your point light to ignore those branches. See a great write-up here. alternatively, as a brute force approach, you could render lights before you draw your branch (though you should REALLY use the mask approach above): // draw all objects that should create shadows ...


1

For path finding, A* (pronounced a star) ought to fit your situation real nice (for people who don't know what binding of Isaac is, it's basically the original legend of Zelda). For avoidance, I can't think of any named algorithms, but I think it will basically be pretty simple to code up some heuristics (rules) to where if an enemy is in the path of a ...


0

Subtract the box position from the mouse position, normalise that vector and apply that as force You can multiply the normalised vector by a float to increase the force.


1

You need to specify the width and height when you draw the texture. batch.draw(texture, x, y, width, height); In your case you want to set the width and height to one since one wall tile is one world unit big. Because you don't specify a width and height the batch uses the width and height of the texture. That is why it covers 16 world units instead of ...


1

Adding to what Erez said, you can make any game without using a Viewport and just scaling your textures to a fraction of the screen size, but most of the time using a Viewport is a better option because it scales everything for you. Although you can use any measurement for the game width and height, I like to choose a target resolution for my game ...


1

What I ended up doing was having one Viewport that was an ExtendsViewport for just the joysticks. Then I added the pause button to the screen without using a table and manually set its size to a fraction of the physical screen resolution. This isn't a great solution because it required another Stage that didn't use a Viewport and since I had another Stage ...


0

From here, you can see how to use the touchUpmethod that is in the InputProcessor interface with the GestureListener that you already implemented. For what are you asking, it should be something like this: public class Inputs implements ApplicationListener, GestureListener, InputProcessor { boolean isFling= false; //A lot of code with the ...


0

I'm just starting out with lighting myself, but one of these two solutions might help you. set an ambient light to brighten up the world: rayHandler = new RayHandler(world); rayHandler.setAmbientLight(new Color(.1f, .1f, .1f, .5f)); or allow the light to ignore bodies: pointLight = new PointLight( ... ); pointLight.setXray(true);


0

Not directly, but you could create a font for libgdx from a .otf using the Hiero tool to convert your font, or create one at runtime but (like the author of this site says), it's something that you should try to avoid. An example of how to load an .otf font can be found here


0

You are allready on the right path, Viewport and Camera are what you are looking for. If you take a look at the different Viewporttypes, there are some, which support virtual screen sizes. That means, that you can say how big your Viewport is and Libgdx will "scale" it up to the Game-Window (or to the screen, if fullscreen). So when creating a Viewport, all ...


0

Here's what I would do in this situation.I'm not using libgdx myself, but I'll give you some pseudo pseudo code. If you haven't already, make a separate class called something like TileMap In that class, create the following variables. public int tileSize public int tilesX public int tilesY public int[,] map The map variable is a two dimensional integer ...


-1

When you draw a shape, there is sometimes a degree parameter (at least when you draw a rect) http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html#rect-float-float-float-float-float-float-float-float-float- EDIT: also, any libgdx Shape Class will have a rotate function. Maybe instead of keeping your ...


0

The render() methods of ray handler should not in the batch.begin() and batch.end() methods. public void draw(Batch batch, float delta){ super.draw(batch,delta); batch.end(); ray_handler.render(); batch.begin(); batch.draw(Something......) } Above codes are working properly. The Result looks like this


2

The skewing is because of how the viewport is setup, try changing it to something like this; @Override public void create() { ... bodyDef.position.set(0, 0); // Let this be at origin for now, it's easier to debug ... camera = new OrthographicCamera(200, 200 * ((float)Gdx.graphics.getHeight()/(float)Gdx.graphics.getWidth()); ...


0

In your update loop: You first handle the input from the user and move him accordingly. Then, you check for collisions with the walls and identify which wall/walls collide with the player. To improve the efficiency of that, instead of checking every single wall in your game, you can check only the walls close to your player and check if there is a ...


1

I think problem is that you are using the size variable instead of the current count of the items that the array contains, in your for-loop. Example for-loop you should use: for(int i = 0 ; i < count ; i++) playerUnits.get(i).doSomething();. When you create an array, its default size is 16, even though it contains 0 items. As seen from the Array source ...


0

To render in a seperate class create a Renderer.java file with a single method named render and create an instance of it in the create() method of your main game class called Renderer renderManager = new Renderer() (filling in any constructors you need). In the render() method of your main game class call renderManager.render(). Now any code that would ...


1

I had the solution for awhile, but I forgot to post. Here's the method to move a list of enemies towards the player. public void moveAlien() { for (Aliens a : aliens) { //List of Aliens (Enemy) Sprite s = a.getSprite(); //Get current enemy's sprite float targetX = spacemarine.getX(); //Player's X float targetY = spacemarine.getY(); //Player's Y ...


1

It is absolutly possible. Here's a simple class that, when called, will save a screenshot of the main graphical context: public class ScreenshotFactory { private static int counter = 1; public static void saveScreenshot(){ try{ FileHandle fh; do{ fh = new FileHandle("screenshot" + counter++ + ".png"); ...


1

Try this: package com.mycompany.mygame; import com.badlogic.gdx.*; import com.badlogic.gdx.graphics.*; import com.badlogic.gdx.graphics.g2d.*; import com.badlogic.gdx.math.*; public class MyGdxGame implements ApplicationListener { public float x; public float y; public float w = 50; public float h = 50; Texture texture; ...


1

Libgdx does not handle this itself, you need to take care about collision detection + collision response yourself. One possible solution would be Box2D, a 2D physic engine. It takes care about forces, mass, friction and other physical things. It also detects and handles collisions for you. It is also possible to let Box2D just detect the collision and notify ...


0

Using SpriteBatch is likely going to be the best option. Passing your batch as an argument to another class' method is generally not going to have any noticeable performance impact. This is also a very easy way of going about the problem because you can just call batch.draw() on your textures inside the desired method.


0

I wouldn't recommend you creating texture atlas manually. With only two textures it looks like this: atlas.png size: 1024,256 format: RGBA8888 filter: Linear,Linear repeat: none player rotate: false xy: 404, 4 size: 400, 174 orig: 400, 174 offset: 0, 0 index: -1 tank rotate: false xy: 2, 2 size: 400, 176 orig: 400, 176 offset: 0, 0 ...


1

I am not 100% sure that this will solve your problem but it seems that you forgot to register the PositionMessage class. Be sure to register it in the same order on the client and the server and also, do not register the server and client classes.


0

You don't have to provide the host address in your server code on Kryonet. Your computer network has its own IP address which is used by Kryonet when you start the server. So on client code, when you start the client you put in the IP address (127.0.0.1) in case where both client and server are on same network. In the case when server and client are on ...


2

In your DesktopLauncher it's not enough to just new up a LwjglApplicationConfiguration, you have to pass that along with your Game instance to the constructor of a LwjglApplication. Try changing your main method to this; public class DesktopLauncher { public static void main (String[] arg) { LwjglApplicationConfiguration config = new ...


1

What's Happening This is completely accurate physical behaviour, which can be explained using a free-body diagram and a little high school physics1: The mass of the block is m and g is the gravitational constant. Fa is the applied force. To understand why the block is not moving, we can write out the force balances in the x and y directions. x-Momentum ...


0

Most probably that's because of the loss of OpenGL context and the way Android handles Activity finish (process/task of the app may not be destroyed when main activity is closed). Check out this Stackoverflow answer for more details: http://stackoverflow.com/questions/12508769/libgdx-app-exit-on-android-not-closing-application


2

One thing you could try is to draw the border as a line with a thickness first, then draw the inner part of the circle as a filled shape; shapeRenderer.begin(ShapeType.Line) Gdx.gl10.glLineWidht(borderWidth); shapeRenderer.setColor(borderColor); shapeRenderer.circle(x, y, radius + borderWidth); shapeRenderer.end(); shapeRenderer.begin(ShapeType.Filled) ...


0

Since you seem to be just starting out, I'll give you the simplest approach. First, define rectangles for all of your game objects (including your player) which will serve as their collision bounds. Once you've done that you will need a method that tests for collision between 2 rectangles (if you used the LibGdx rectangles then you can simply call their ...


1

I just had the same problem This is my solution public class SpriteAccessor implements TweenAccessor<Sprite> { public static final int ALPHA = 1; @Override public int getValues(Sprite sprite, int tweenType, float[] returnValues) { switch (tweenType) { case ALPHA: { returnValues[0] = ...


0

I have found some sort of a workaround this, but I am not sure if this is a good way to code. When a key is pressed, I set the angular velocity to 10 and then at every update, I ask it to check if(weapon.getAngle() >= Math.PI / 2) { weapon.setAngularVelocity(-10); } if(weapon.getAngle() <= 0) { ...


0

You can also use CodeAndWeb's TexturePacker - it comes with a whole bunch of optimizations to reduce artifacts on tile borders etc. Not free but work a try.



Top 50 recent answers are included