Tag Info

New answers tagged

0

Look here, you're using the listener wrong: http://stackoverflow.com/questions/11373390/button-clicklistener-is-not-working-in-libgdx-game (you're not overriding its methods, I suggest looking up some more information about listeners and especially this one). And use this question to make sure you're adding the stage and the actor right and that you're ...


0

Based on my memories and for example this: While it's difficult to understand the complicated ANDs and ORs, it seems clear that you forgot to check for the jumpButton being pressed after the other buttons. With leftButton and rightButton, you have Gdx.input.isTouched(0) as well as Gdx.input.isTouched(1) (with OR inbetween them, so I take that as you're ...


0

Your best bet is to extend the Image class and add a touch listener. Add this code into your Image subclass: private void addTouchListener() { this.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { YourClassName.this.wasTouched(); } }); }


2

After some research and testing, I've now managed to resolve my own issue. The problem lied within memory management. I followed this tutorial Stiegert and got inspiration from his SoundManager class to create a new SoundManager of my own that uses LRU Caching. Thanks Alexandre Vaillancourt for the assistance


0

Not exactly sure what is going but I always create a stage with a viewport (with or without a camera). Something like this: stage = new Stage(new ScreenViewport()); table = new Table(); table.alight(Align.top | Align.center); table.setFillParent(true); //To have it fill the screen TextButton button = new Button("Click me", skin); button.addListener(new ...


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


0

I can't help you exactly with code because I'm not sure where all your variables are coming from. If you provide some context to this code, I can help more specifically. In the meantime, take a look at this picture: If you know how far you want the sprite to travel, and you know the angle. You can calculate the x and y distances using the formulas from ...


0

Have you consider using chunk of pixel in your second point to get better performance? If you search for a different aproach you can investigate Cellular automaton , starting from lights chunk for each neighbour lite them according to distance and material repeat for its neighbours ...


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


0

Add the particle effect to a group with transformation enabled (default).


0

You need to add the correct JARs to your project. For example, you can see from this Gradle/Maven repository search that there are both gdx-freetype and gdx-freetype-platform JARs. To add them to Gradle, you just need to add the dependency name and version under the dependencies section.


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


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


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


0

Why don't you just use the rectangle class for this? if (tileRectangle.overLaps(playerRec)) { //Overlapping, do not move in the direction you currently want. } Since you are using a tilemap you do not have to check each and every rectangle. Just the ones around the player. You setup a y loop with a inner x loop and set the start and end coordinates in ...


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


0

As you are using a pixmap you can clip it easily. I am not on desktop so I am giving a pseudo code for now. for( int x = player.x - desiredMapWidth / 2, i = 0; x < player.x + desiredMapWidth / 2; ++x, ++i) { for( int y = player.y - desiredMapHeight / 2, j = 0; y < player.y + desiredMapHeight / 2; ++y, ++j){ Color c = fullMinimap.getPixel( x, y ...


0

You're assumption that you do not need any physics is wrong, anytime you are dealing with moving objects in 1D, 2D, 3D... environments and you need to detect if two objects will collide then you are doing physics calculations. You can not get away from it. Returning true or false is easy, but figuring out if a collision has happened or not can range from ...


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


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


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


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


0

Well if you are incorporating zoom with your camera you have to multiple the rectangle by that. It also depends from where the camera actually zooms, I believe this is the center of the camera but it might be bottom left too. Something like this should leave you with the correct rectangle size. shape.rect ((Constants.RENDER_WIDTH - 500) + ...


0

I'll assume you are talking about a 2D game or at least a 2D UI. Well, if you think you need to create graphics for 1920x1080 then you should go for it. If you setup a viewport properly libgdx does all the scaling for you. Personally I have my viewport represent a 1280 x 720 area. You won't see any difference on phones, I barely even notice the difference on ...


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.


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


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


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


0

Collision detection shouldn't depend on input. You should aim to make your movement and collision systems as generic as possible. Not only that but I'm seeing an issue with the logic that happens during your frame. You seem to be doing something along the lines of: //Detect input //Detect collision //Move according to facing direction //Draw ...


0

About textures loading, yes i suggest you to make them static in the AssetManager class and then declaring them in the "level" class with Texture letterA = AssetManager.letterA and so on. Same goes for the dictionary (i never had to process a .txt file so i don't know if you're going to declare it as a String or else..). I usually make static every asset ...


0

I took some time to think about the issue and realized that logically, there is no purpose for disposing the World or re-initializing it whenever a new Level is loaded it seems a lot better to dispose and reinitialize the world when a new Level is loaded - thanks to @Shiro for helping me see this. I won't have to manually clear all of the World's bodies, ...


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:


0

I believe for android you need to have an assets folder with all of the assets loaded into it, this assets folder would be in the android project rather than the core project. Desktop, HTML, etc all use core project assets so they would work fine, but android needs its own assets folder. do you have one for it?


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


0

I've run into this problem on certain displays, while it had worked just fine on other displays. My specific situation was a little different and was that I was trying to switch from 1280x1024 fullscreen to 800x600 windowed and the screen went black during the transition from fullscreen to windowed mode. A borderless window configuration enveloping the ...


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


0

As far as I am aware, the setting genMipMap for TextureAtlas is not available. If you're packing your images using TexturePacker to create your atlas, you can pass it Settings: TexturePacker.Settings settings = new TexturePacker.Settings(); settings.combineSubdirectories = true; settings.filterMin = Texture.TextureFilter.MipMapNearestLinear; ...


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


0

You don't want to use setLinearVelocity for horizontal movement as that set's the velocity to a value it will cancel out any force applied because of a jump. For moving left and right you want to use either applyForceToCenter (like what you do for your jump), or applyLinearImpulse. You might want your code to do something like this to limit the ever ...



Top 50 recent answers are included