Tag Info

New answers tagged

0

The way Box2D resolves collisions results in it working very poorly with tiles maps where the tiles are converted into square bodies. It is best to have a separate layer for specifying objects to use for collision which is completely separate from the graphical information for the tile map. You can then use this object layer to generate the Box2D bodies ...


0

This question is confusing but my understanding of it is something like this should solve your problem in the draw method ... this.camera.update(); // update the camera var y = sprite.getY(); // determine y value of map if(y<100 || y>=200) // if y is in usefull range { // render the tile map this.renderer.setView(this.camera); ...


1

Easiest way is to set the visibility to false tiledMap.getLayers().get(index).setVisible(visible); EDIT: Reference to the libGDX API http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/maps/MapLayer.html#setVisible-boolean-


1

Unfortunately, there is no magic: the only good way is to implement resolution independence yourself. While libgdx may be of some help, it's not going to solve your every problem. For my NoThree puzzle game (see profile for link), I drew my graphics in Inkscape and I exported several resolutions (144x144, 72x72, 48x48) for each texture (the font is also ...


0

If i understand this correctly then you take some data and then as part of the rendering process you distort the postition of that data ... this.camera=new OrthographicCamera(); this.camera.translate(map.getMapPixelWidth()/2, map.getMapPixelHeight()/2); this.camera.update(); view=new StretchViewport(map.getMapPixelWidth(),map.getMapPixelHeight(), camera); ...


1

Actually it's already present in Vector2 class. You can use something like this: Vector2 touchPoint = new Vector2(211,312); // random touch position Vector2 center = new Vector2(world.getWorldWidth() / 2, world.getWorldHeight() / 2); // center of the world float width = touchPoint.sub(center).len(); // length of resultant vector float angle ...


0

There are two [main] types of controller input. There is DirectInput, and there is xInput. PS3 controllers use DirectInput, while xInput is Microsoft's choice (they made it for the xbox, I think). Both of these controllers are supported in LibGDX. However, they are different in how you get data. For example, DirectInput doesn't handle analog trigger buttons, ...


1

This is very simple, actually. You don't need to translate the camera (that is dealing with Matrices, I think?) using the "translate" method. You can simple set the camera's position to your sprite's position (assuming you use the x-y coordinates where (0, 0) is the bottom-left corner. Or extend the "Sprite" class; either way should work). In your camera ...


0

Are you sure this is not working? I tried to reproduce and it's working just fine. (*) You wrote that the TextFieldListener is just working fine, so I assume you've set the InputProcessor to the stage, right? Just in case you did not and did some black magic (or rather for others who might face a similar error): Gdx.input.setInputProcessor(stage) (*) ...


0

Put your ImageButton in a table. Set the size of it. Add the table as an actor in your stage. Here is an example: ImageButton. ImageButton Style btnStyle new ImageButton.ImageButtonStyle (); btnStyle.up = skin.getDrawable ("your image"); btnB = new ImageButton (btnStyle); stage.addActor ( table ); table.add (btnB).size (150, 200);


1

I have never used a viewport without a stage, but replacing width and height with the calls to Gdx.Graphics.getHeight/getWidth that you are using causes the same behavior you are experiencing. Removing those calls and using the passed values should fix your problem. public void resize(int width, int height){ stage.getViewport().update(width, height, ...


0

You need to transform the world space rotation vector to model space before applying the rotation. Vectors are transformed with inverse transpose of the matrix, i.e. v'=transpose(inverse(M))*v Because models generally define model->world matrix you need to invert this to get world->model matrix. So you need to calculate v' = ...


0

The question is a little stale, but in case it still helps: After you run ./gradlew html:dist to generate production code, you want to copy everything inside ./html/build/dist/ to your server. Running that command produces the code in that directory. The code that's under the war directory and that has a Tomcat-like structure, I believe all that is for ...


1

You're monster locations are based on a random number: monster.setPositionXY((r.nextInt((int) width)), (r.nextInt((int) height))); You initialize width and height with: width = Gdx.graphics.getWidth(); height = Gdx.graphics.getHeight(); So your monsters will be placed on a random location in screen coordinates. Now I'm not sure about your drawing code ...


0

The SpriteBatch has its own internal camera. Are you also setting the batcher to use the camera's combined projection matrix by calling: batchM.setProjectionMatrix(camera.combined); The problems you could be experiencing, could perhaps be explained by the fact that collisions only appear to be happening on screen, but actually aren't as the map ...


0

You should definitively use a quadtree as Hjorthenify suggest. see: handling collision detection with a quadtree At each frame you may reconstruct your quadtree and then for each collideable entity you retrieve the entities contained (or intersected) in the same area (NE, NW, SE, SW). For exemple : public void checkCollision(Entity e, ...


3

Your pathfinding should return a list of way points to reach your objective for each unit. Since you are making a turn based game, I am assuming that the unit movement is like a chess piece. It is either on "this" tile or "that tile, and not in between. If this is the case you might end up with the scenario where a units movements runs out in the middle of ...


0

thanks for the answer, I'm sure it would have worked perfectly. however as i was implementing it i came across a Bullet Physics built in function. BtRayCastVehicle has vehicle.getForwardVector() thanks for your help in this matter


1

I fixed the issue by changing the global coordinate system to the box2d one. Now the local 0,0 coordinates of my entities correspond to their center coordinates and they represent meters instead of pixels. EDIT (some clarifications): I now translate them in the render system (because this is really the only place where I need pixel coordinates): // get ...


0

If you want the ray the vehicle is currently moving upon, you want the difference between the current position and a previous position, then normalize it for the direction of the ray (the start of the ray being the current position). Alternately, you can make a normalized copy of the velocity vector for the direction with and current position as the start of ...


1

To get the rotated sprites coordinate simply call the getVertices() method. For example: sprite.getVertices()[SpriteBatch.X2] Gets you the X coordinates of the top left corner. The same call but replacing X<number> with Y<number> gets you the Y coordinate. The corner numbers go like this: 2-3 | | 1-4


1

Don,t do any thing just set the scale of the font and it will work for all type of device font.setScale( .9f,.9f);


1

You should use BitmapFont.drawWrapped. public BitmapFont.TextBounds drawWrapped(Batch batch, java.lang.CharSequence str, float x, float y, float wrapWidth) All you need to do is set the wrapWidth variable as ...


0

Write multiline text in LibGdx To write a multiline text with bitmapFont just use this following code- String completeText= "In this text there are multi lines\n.To write this race in your game \n you have to write in proper manner. \nYou have to make the text look better ."; font.drawMultiLine( ...


0

No need to take an extra class for Input just write the following code in render method :- if (Gdx.input.isTouched()) { Rectangle touchRectangle = new Rectangle(Gdx.input.getX( ), Gdx.graphics.getHeight() - Gdx.input.getY( ), 10, 10); //just check if your finger overlaps on your ...


0

To get the count of your game launch first make a LocalPreferences class and write following public class LocalPreferencees{ Preferences prefs; public LocalPreferencees() { prefs = Gdx.app.getPreferences("GAMECOUNT"); } public void setCount (int count) { prefs.putInteger("COUNT",count); prefs.flush(); ...


0

Yes you can write your all code of your dispose in hide method. But if the problem still occurs then you can do your all dispose work just before when you load your Assets and make the SpriteBatch null at the starting and then make its object. Like : AssetLoader.dispose(); AssetLoader.load("path of texture","Type.class"); and spriteBatch=null; ...


3

Change your thought process from "Moving 7 units" to "Applying a velocity of 7 units" and you can come up with something like: velocity.Y = -7; position.Y += velocity.Y; Now if we take this and we want to apply acceleration every frame we can simply update the velocity every frame. accelerationRate = 2; //arbitrarily picked - no significance velocity.Y = ...


1

position.y -= 7f; change 7f to a variable var fallspeed = 7.0f; position.y -= fallspeed; increase the fallspeed every update var fallspeed = 7.0f; var gravity = 5.0f; position.y -= fallspeed; fallspeed += gravity; This creates a linear acceleration. Gravity on the other hand isnt linear, so you might wanna try something like this var fallspeed = ...


0

initialScale looks like a constant used to scale everything in the game. zoom function calculates originalDistance / currentDistance value, applies it to Camera and prints it out. It's hard to tell more without seeing other affected code.



Top 50 recent answers are included