Tag Info

Hot answers tagged

8

TextureAtlas#findRegion(String) returns a region with a name that matches the name specified. It does not copy the region, therefore any changes you make to the region will be reflected in the TextureAtlas. To overcome this issue, simply instantiate a new TextureRegion object and pass it the region found inside your TextureAtlas: background1 = new ...


3

I think it will work if you combine your input listener with: animation.isAnimationFinished(stateTime); While playing animation ignore attack input and let it just continue playing. When the animation finishes you can respond again and start a new animation by reseting the stateTime. But I would also have in mind that the player can move meanwhile and ...


3

In the second case it is not drawing because the constructor with no arguments doesn't set a width and height for the image, however the constructor that takes the drawable obtains the values from it. To fix in your case: Texture texture = new Texture(Gdx.files.internal("cookie.png")); Image itemImage = new Image(); itemImage.setPosition(10, 10); ...


3

If you would follow the second strategy, changes made to the Vector that got passed as parameter "v" will also be made to "vector2", since they are the same object. You should have a look at this question: http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value In Java every object is an reference, so you need to copy, for ...


3

This is because movementSpeed should be how many units you would like your character to move per second (so your movement speed should be 6, for 6 units per second), and multiplying that by deltaTime in LibGDX will give you a value that will achieve the movement of movementSpeed per second. Delta times work differently depending upon how they are ...


3

Try this: @Override public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) { super.keyboardFocusChanged(event, actor, focused); if (!focused) setOnscreenKeyboardVisible(false); } Otherwise you could go for a better work around. You place a big clickable transparent actor behind everything. When you click anywhere ...


2

You should register the pointer you are walking with. Pointers are the number of touches on the screen and they are provided by the listeners you are using. I think if you change this it to something like below you can get it to work: @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { if (int pointer != 0) ...


2

Box2D has a Java library. It might be a bit more than you need but it's pretty robust and used in all sorts of projects. Maybe someone else can recommend a better library solely for collision detection. If you want to roll your own solution, which would probably be better if you want to keep it simple, you'll need to look into Oriented Bounding Box (OBB) ...


2

As mentioned above, you can start and stop a SpriteBatch in the same draw-method, also for transparency you need to enable BLEND. Here's what I did with one of my UIs. batchstuff... spriteBatch.end(); Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); ...


2

Basically, what a hashmap does is store the objects in a random location in your memory. Complexity is O(1) which means that it will always take the same amount of time to retrive an object from the hashmap. The amount of time depends on various factors. This might be quite fast for few objects, but as soon as you start drawing scene with hundreds of ...


2

I found the solution, so I think I should write here for other ones later. First I download the source code of box2dlights. Then open BaseLight.java and find "segments" member variable. This variable contains all information about what I was finding. This code below is just for debugging purpose: rayHandler.setCombinedMatrix(camera.combined); ...


2

Menno Gouw's answer is correct and is probably the way to go in most cases, but just in case someone runs into my problem where that solution might distort the positioning of other actors I thought I'd post how I solved it. First Create an "invisible" button: ImageButtonStyle style = new ImageButtonStyle(); style.up = null; style.down = null; ...


2

A lot of great Libgdx extensions have been added to the maven repository such as freetype, tools and many other great libraries. This means you can add extensions in a blink of an eye, at least if you used the gradle LibGDX setup. In your case you want to add freetype, look it up in the link above and select the version you need. Now select the tab Gradle ...


1

I personally never calculate an angle like that. I like to work with vectors, it might be slightly less efficient but this way you can do it step by step, it gets more readable and easier to understand. So what is a vector? A vector is essentially a direction and a magnitude together. Often in games it is used as a position data structure too but ...


1

One option is to give the Wolf class a disguise function. This could look something like this. class Wolf { void disguise(Animation p_target) { this.animation = p_target; } void animate() { play(this.animation); } void reveal() { play(this.animation.reveal); } } Another option is to create a child ...


1

The reason why scrolled is not working is... To activate scrolled in Scene2d, we need this one line stage.setScrollfocus(actor);


1

Are you assigning cheetahX to something or drawing with it? You did not post your drawing method or where you use cheetahX further on in your code. I predict that Cheetah holds your InputHandler then you need this: public class inputHandler implements InputProcessor { private cheetah cheetah; private gameWorld myWorld; private float cheetahX; ...


1

You should use a table to setup. Tables can be aligned and there cells sizes can change. You can do something like: table.row(); table.add (tb).width (tb.width*scale); What I did here is setting the cell with to the size of the table times a scale. You can set various variables on table cells. A table is a container widget and you have more of these. A ...


1

I hope I am understanding your question correctly -- if not let me know. I believe the following is where you are unprojecting the coordinates: @Override public boolean mouseMoved(int screenX, int screenY) { worldCoordinates = camera.unproject(new Vector3(screenX, screenY, 0)); return true; } Because you are using a viewport, you must add the ...


1

Below code works for me, I get the message when pressing the back button. if (Gdx.input.isKeyJustPressed(Input.Keys.BACK)) { Gdx.app.log("Debug", "Back pressed!"); } Are you calling below method before the one above? Gdx.input.setCatchBackKey(true);


1

For normal cases, sprite order is determined by the Spritebatch.draw() call order. If this is the case: spritebatch.draw(apple); spritebatch.draw(mango); then apple will be drawn first and then mango will be drawn on top of that. So mango will overlap apple.


1

On my version (1.6.3) there is only one SpriteBatch method that takes 10 parameters. /** Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. The * rectangle is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle * should be scaled ...


1

I've managed to get it working by fiddling around and it would seem that this works as I wanted. `shape.setColor (Color.WHITE); shape.rect ((Constants.RENDER_WIDTH - 500) + (camera.position.x - (camera.viewportWidth * camera.zoom) / 2) / 30, (camera.position.y - (camera.viewportHeight * camera.zoom) / 2) / 30, (Constants.RENDER_WIDTH * camera.zoom) / ...


1

LibGDX is formally a Framework and does implement the game loop for you. getDeltaTime() does smooth out over a number of frames. Instead you could use getRawDeltaTime(). I have seen some people get smoother results by capping the framerate to 30/60 instead of using getDeltaTime.


1

From the Terminal, run: gradlew --refresh-dependencies Also, in the Gradle tool window, you can refresh all Gradle projects, though you should only need to do this if you make changes to your Gradle scripts:


1

Yes, libGDX does optimize in that area, but that is irrelevant to the code you've written here. In your first part where you drew off-screen, you went and drew off to position 50000 that would be taxing to the computer, but the fact of the matter is that your Gdx.graphics.getWidth() / Gdx.graphics.getHeight() is unlikely to be ever 50000 unless you are ...


1

If you would use the Type field instead of the Name field, then you could set a color for each type of object in the preferences. It would also autocomplete in this field for the types you have defined. But maybe a better way to make your objects visually more recognizable, especially when the size is irrelevant, is to use tile objects instead of rectangle ...


1

One thing you can do is to use multiple layers. Instead of using the Name tag of the object/collider to identify the type of the entity to be spawned, you use the layer name, so you would have Player-layer, Monster-layer, Item-layer etc (and everything in that layer is implicitly of the type specified by the layer). Then you can set the Color of the layer, ...


1

All current implementations of TiledMapRenderer, such as BatchTiledMapRenderer, do not have the functionality to render any MapObject. You'll have to create your own implementation of TiledMapRenderer. This should get you started: public class TextureMapObjectRenderer extends OrthogonalTiledMapRenderer { public TextureMapObjectRenderer(TiledMap map) { ...


1

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



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