Tag Info

New answers tagged

1

After much frustration, I found out that I had made a folder the same name with the text file by mistake!! After deleting the folder all works fine, thank you for replying!


1

I had this class in previous project public class ExtendedCamera extends OrthographicCamera { public Player player; public ExtendedCamera(Player player) { super(Constants.WORLD_WIDTH, Constants.WORLD_HEIGHT); this.player = player; } public void followPlayer() { if (player.body.getPosition().x - position.x > ...


0

You are rotating the sprite using an int, 0-360, instead of a float. Try doing sprite.setRotation(angle/360f);


0

First, you need to find which blocks should move move, given a particular clicked cell. You'll probably want to use a floodfill algorithm of some sort for that. Once you have your list of tiles, move them all one after the other before doing anything else. The way I would do that would be to change the move function so that it takes another parameter ...


2

When centering the camera using lookAt you need to clamp the y value to be the max of the body's y and the y of the ground plus half the viewport height (possibly adjusting for the height of the ground). Something like this might make sense; float x = body.getWorldCenter().x; float y = Math.max(body.getWorldCenter().y, ground.getWorldCenter().y + ...


1

In order to make the title appear with the image you need to use the location of the image plus an offset. The reason (PPlane.WIDTH / 2) - (title.getWidth() / 2) works to center the image is because you're finding the midpoint of the PPlane and then subtracting an offset equal to half of the title's width which has the effect of centering the image ...


0

There is no exact (and short) answer for what you are asking, but I'll try to help you for some parts that you need to know in order to achieve this. for simplicity, I'll skip and resume a lot of code * First part is How can I render text?. There are plenty of tutorial in internet. A fast example is the Scene2D library (already in libGDX yei!) using the ...


0

I have to agree with Xkynar on this, but I'd like to add something. In order to keep track of the different animations, you can use the libGDX Hashmap in order to store each Animation object under a string name, like "running" ,"walking", or whatever. Each animation can then be accessed by requesting the name of the animation in the Hashmap. If you'd like ...


2

Emanuele Feronato did a tutorial on this some time ago, you can use it as a base: http://www.emanueleferonato.com/2012/03/05/breaking-objects-with-box2d-the-realistic-way/ To sum it up: Listen to collisions between your breakable body and the bodies that can break it; When collision happens, get the velocity of the body that can break the other and ...


0

If you use polling, use Gdx.input.justTouched() rather than Gdx.input.isTouched().


0

I actually just figured it out, by checking all the polygons at the same time and returning the index of the polygon with the containing co-ords! The wonders of coffee and cigarettes!!


0

I would do it with Scene2d. You can have your game with a normal game loop and a SpriteBatch to manually update and draw the game and additionally you can have a Scene2d Stage that you can use to display whatever UI components you wish above your game (or below, depends on the order of calling the draw methods). It's a very nice library, great I would say, ...


0

If you ask me it is not a good approach. Good news is you don't have to change too much stuff. Create an ads controller interface in your core module and implement it in your main Android class. So you can pass it to your game class and store it. Then whenever you want you can call adsController.hideBannerAd(); But you should first implement that method :D ...


0

When you create an app with gdx-setup, simply select Android and iOS and de-select Desktop and Web options. If you have created them, just ignore them.


0

With libGDX, you can either create a runnable JAR file or a native application file. To get your app on the Mac App Store, you will need to go with the second option. This can most easily be done with a tool called packr. What it does is it packages your JAR file (all the code and assets) with a JRE (Java Runtime Environment) into a standalone .app file ...


1

As described here (last chapter), please check the value of the field renderCalls in your SpriteBatch (you have only one unique SpriteBatch instance right ?), this should tell you the real number of draw calls that the batch has made. If you have more renderCalls than what you would expect then maxSpritesInBatch value is too low or your sprites have ...


0

Adding an answer to my question above. what happened was I was thinking in exact pixel coordinates. When I should have thought of world units when using viewports yes thecamera is centered at (0, 0) by default but the world width and height was only 100. There is a transparent space at the bottom left of my image. That is why even though it is also at ...


2

I spent a good while looking how to implement Box2D in Android studio, so for anyone else in the same boat, or just looking to implement Box2D - here goes. For implementing Box2D into your java code/framework, Box2D is tuned to work with numbers between 0.1 and 10 (it works in meters), quoting from the Box2D manual: http://box2d.org/manual.pdf Box2D ...


2

It should work if you change these parts in show(): viewport = new ScalingViewport(Scaling.fillY, GAMESCREEN_WIDTH, GAMESCREEN_HEIGHT, camera = new OrthographicCamera()); and add a resize method: @Override public void resize(int width, int height) { int SCREEN_WIDTH = width; int SCREEN_HEIGHT = height; viewport.setWorldSize(GAMESCREEN_WIDTH, ...


1

Use of delta is to smooth your animation or as you said "making it independent of frames". So may be separating animation with the position calculation can solve your problem. For example, First calculate your next position in separate method then show your animation, by adding delta to initial position to final position, without loosing the initial ...


0

Please go through this tutorial, published by libgdx, https://github.com/libgdx/libgdx/wiki/A-simple-game In above tutorial, in "Loading the assets" section, you can change/remove the image (badlogic's by default image) as per your requirement.


0

Because by default Camera sees your game screen from top, having it's 0,0 fixed at top left corner. On the other hand, things you draw in render method, have 0,0 fixed at bottom left corner. To combine your game screen's coordinate with camera's coordinate, you use, batch.setProjectionMatrix(camera.combined); Read this article, written by libGDX ...


0

You need to to point your working directory to the assets folder. Snippet from https://github.com/libgdx/libgdx/wiki/Manual-project-setup The Android project has a subfolder named assets, which is created automatically. Files available to the Android application must be placed here. This is problematic, because these same files must be available to the ...


1

I think if it is invisible and if it is not affecting gameplay it is acceptable. But if you want a solution you can set a flag when starting collision detection, when the flag is true don't move your objects and store how amount they should move. If a collision happens extract how much it should go back from stored value and apply the stored value then set ...


1

What you want to do is determine how much the two AABBs overlap and then move them apart based on that amount. You already have an overlaps method. If you tweak that to return the amount that the AABBs overlap (on each axis) then you can just move your player back by that amount. That assumes that what you're colliding with doesn't need to be pushed back ...


0

I would say that No, you can't do that easily with the particle editor. It would require the synchronisation of three values: xOffset yOffset velocity In the libGDX particle effect implementation these are generated using RangedNumericalValues and ScaledNumericalValue, and they provide a new value independently of each other. The offsets are ranged, so ...


1

Instead of casting rays in 360 degree fashion, cast rays to the corners of the tiles in range of the lightsource. Sort the angles from the light source to the tile corners and do a 'sweep'. You can optimize the algorithm to look for the nearest tiles first and ignore angles for culled tiles: A--B E--F o |T1| |T2| C--D G--H Angles would be ...


0

Okay so I solved it: 1. Make sure glEnable(GL20.GL_BLEND_COLOR); is on and the blend function is Gdx.gl.glBlendFunc(GL20.GL_BLEND_SRC_ALPHA,GL20.GL_ONE_MINUS_SRC_ALPHA); 2. Edit the light texture in something like GIMP to double check that your background is transparent. 3. MOST IMPORTANT Make sure the lightFramebuffer is Format.RGBA4444 or ...


0

On the resize event method in your ApplicationListener (the main game class) change public static width and height integers like so: WIDTH = Gdx.graphics.getWidth(); HEIGHT = Gdx.graphics.getHeight(); float scale = (float)prefferedWidth / (float)WIDTH; WIDTH = (int) (WIDTH * scale); HEIGHT = (int) (HEIGHT * scale); The prefferedWidth is the ...


1

I used this solution to make a water distortion effect. You could use the sin waves vertically instead of horizontally to possibly achieve your effect. I draw what might get distorted onto a FrameBuffer. I make regions of the buffer texture that will be redrawn with a distortion shader applied. GdxGame.java void create(){ scaleX = ...


0

You're mixing terms and techniques here, a 2D-Texture has no z-dimension. What you actually want for your normal-mapping is to fetch the texel t from the image using the usual 2D texture-coordinates and use these color-values t.rgb as a normal-vector.


4

One option is to use a wake lock. Example from the docs: PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wl.acquire(); // screen and CPU will stay awake during this section wl.release(); I've got this answer from this stack overflow post. ...


0

A guess here, but logging on the same thread as your rendering work, before you send gpu instructions, can add synchronous disk latency? Possibly in a sporadic fashion if it's buffered and dumping. @Override public void create() { batch = new SpriteBatch(); img = new Texture("badlogic.jpg"); } @Override public void render() { ...


1

The solution suggested by Sebastian would work, but you'll end up with a lot of code just for a "fade out/fade in" animation. Libgdx has built-in functionnalities for that in Scene2D, you should use them. (Actions, Stage, Actor) That would make your code as simple as that : myPlayer.addAction(Actions.sequence(Actions.fadeOut(0.15f), ...


1

Why not set the alpha value of the sprites directly via sprite.setAlpha(float)? Of course you would have to call that by your rendering method and calculate the amount of alpha alteration using deltaTime. https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setAlpha-float-


0

I don't believe there is a built-in function for this. You have a few options though: Use a 9-patch for table background with a border (thats what I do) Place another table underneath the main table, and make the size a bit bigger so you can see the edges, giving the impression of a border. This is probably your best choice since you want to control ...


0

I found a quite nice tutorial on how to do this here: http://tikotepadventure.com/simple-water-reflexion/ The first part is of your interest, the rest maybe too to give a cool effect.


0

Sorry yesterday I was a wreck :) but I just found a solution for you. Simply build up the button yourself... lol, I cannot believe I didn't think of that yesterday? Button button = new Button(); button.setDebug(true); Button.ButtonStyle style = new Button.ButtonStyle(); style.pressedOffsetX = 100; Label label = new ...


1

As the comment says offset only effects the children, i.e the text inside the button. What you need to look at is this piece of code: buttonStyle.up = new TextureRegionDrawable(settingsAtlas.findRegion("achievements")); buttonStyle.down = new TextureRegionDrawable(settingsAtlas.findRegion("achievements")); Since you set the same image for up and down you ...


0

This is a post by @OrangePixel for one way to make efficient lightning with Libgdx. It describes a simple technique. You can put alpha blended Dot above the map and make it seem like a lightning effect. The article is interesting and all the thanks go to the author! http://techblog.orangepixel.net/2015/07/shine-a-light-on-it/


1

Make sure you resize the viewport when you resize the window. You should be able to override the function 'resize' in your ApplicationAdapter. public class GameClass extends ApplicationAdapter { @Override public void resize(int width, int height) { YourUIStage.getViewport.setScreenSize(width, height); } }


1

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


2

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



Top 50 recent answers are included