New answers tagged

0

I was searching for an answer because I had the exact same problem, and I thought of a great and light workaround. When you create your method of what happens to your B2D Body after the collision, just create an object and assign it to the obects' .getUserData. Then when the collision is called again, you can "save yourself" with an "if statement".Example: ...


0

Actions.sequence() is a convenience method to create a SequenceAction object. You have to give this action to your Actor for it to do anything. //addAction() is a member of Actor this.addAction(Actions.sequence(...)) However, this is probably not what you want. Firstly, a SequenceAction is an action where it waits for each action to finish before the next ...


0

In Java, every variable that is an object type (i.e any that are not int, float, boolean etc..) is initialized to null. That means unless you store something in that variable via SomeObjectType variable = new SomeObjectType(); //or SomeObjectType variable = otherVariableThatIsNotNull; Then you will get a NPE whenever you call variable.anyFunction() ...


0

Whenever you modify a camera's position, you need to call camera.update() so that it will update all of the other variables that the camera uses. This update call should be done before any drawing is done. In my games, I usually call camera.update() at the beginning of my render function. Second, it looks like you are calling camera.translate(100,100) every ...


0

It seems like you are asking more about image processing and not LibGDX specifically. Once you change the white background to transparent pixels, then LibGDX will draw it without the transparent pixels. The algorithm that you are looking for is called Background subtraction or Foreground detection. I have had some success before (albeit in Android) with ...


2

At least i have found the solution. It includes 2 step : 1- My surface texture wraping was wrong. X axis must be repeated and Y axis must be clamped to edges. The correct one is: surfaceTexture.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.ClampToEdge); 2- When we use "ClampToEdge" wrapping, texture's Y coordinates must be between 0 and 1. So i ...


0

Turns out this was pretty easy. You know the width of the screen, you know the width (and zoom) of the camera's viewport...just math it up: fun Float.metersToPixels(cam: OrthographicCamera): Float { return this * cam.scale } fun Float.pixelsToMeters(cam: OrthographicCamera): Float { return this / cam.scale } val OrthographicCamera.scale: Float ...


1

From my experience, it's not expensive to bind textures. I have a program that binds about 30 textures per frame and it runs pretty smooth. Since you're using only 9 textures and VBOs on top of that, I imagine your game actually runs very well.


1

There may be a better/more efficient way to do it, but an easy way would be to draw a tinted, mostly transparent circle on top of an actor. (Or beneath the actor if you don't want the actor itself tinted.) If you have a white circle texture and want a red aura, then the draw code would look like this Color oldColor = batch.getColor(); ...


1

Yes. It is possible. Any of the scene2dUI widgets, like Table, inherit from Actor. Actor has a setVisible(boolean isVisible) member that will hide it and all of its children and disable any touch events to it. You just have to make sure that your menu or game instructions are in front of your Game view by adding them to your Stage last. You will also need ...


1

You should probably take a look at Scene2D's Window class. Think of it as a screen that just overlays other screens. It's also a Table, which means you can add buttons or any other Actor to it just like any other table. This also means you can directly add it to your Stage, if you wish. A simple pause screen would be something like this: Window pause = new ...


0

I've solved the problem after a bit more analysis. In addition to the suggestion by spectacularbob, I forgot about a line of code that applies damping to the players velocity to make him slide less. This worked well for movement on the x-axis, but resulted in the jittery jumping on the y-axis. I simply changed the following: ...


1

My guess to why it is choppy is because scl() is permanently scaling your velocity by deltaTime each update call. Since deltaTime varies a little from frame to frame, this causes the choppiness. Change the position update to float velocityX = player.getVelocity().x; float velocityY = player.getVelocity().y; player.getPosition().add(velocityX * ...


1

Dont know how your particle system is written but it is very possible that your bottle neck is the communication time between CPU and GPU. Not going to go into too much detail but just know that this operation can be very slow because it causes stalling. Perhaps the idle time you see in profiling is due to that. What a good particle system do is to move all ...


0

So I found the solution and I find it rather odd. Basicly I increase the overal alpha-value with 100*delta. Sometimes the result is >1, and appearently libGDX can't handle an alpha of 1.1, blacking out the screen (drawing at alpha 0.1 propably?)


0

If your class implements InputProcessor: @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { MoveToAction mta = new MoveToAction(); mta.setPosition(screenX, Math.abs(stage.getHeight()-screenY)); mta.setDuration(5f); //moves to new location by this time interval stage.addAction(mta); return false; ...


0

In my experience, Box2D is a little fussy about dealing with things such as line lengths that are shorter than a hard-coded lower limit. I don't recall the lower limits, but you can find the checks in the Box2D source. Box2D will throw an exception which is unable to cross the JNI boundary and brings the whole process down with no explanation. Maybe add some ...


3

I would take a look at glDraw*Instances (Instancing) Also, reducing vertex count for a large amount of small particles is extremely important. I don't know if your using a model or a single 2D texture or what, but some general tips: Use as few verticies as possible. If using transparency in your textures, use glAlphaFunc to reduce blending needed. If ...


0

To fix the aspect ratio (and speed up the shader a bit): void main() { vec2 diff = (v_position + 1.0) * 0.5 - u_mousePosition; diff.x *= u_aspect; // e.g.: (16.0 / 9.0) for 16:9 float distance = dot(diff, diff); // square of distance, saves a square-root if(distance > u_lightRadius_squared)) { discard; } outColor = ...


0

I would agree with using the TweenEngine. It's relatively simple to use and provides a lot of functionality. To tween a value you first have to create a TweenAccessor. It would look something like this for a Sprite: public class SpriteAccessor implements TweenAccessor<Sprite> { //Used to identify what type of tweening you wish to do. public ...


0

After sitting with this problem for hours I finally found out what was wrong. If you set the shader to null on your SpriteBatch, it uses the default shader provided to the SpriteBatch. For me, the default shader was Assets.getDefaultShader(), so when I set the shader to null it just used that shader. I fixed this by simply not settings a default shader to ...


1

you can do like this: In your hud class public jumpButtonPressed = false; buttonJump.addListener(new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { jumpButtonPressed = true; return true; } public void touchUp(InputEvent event, float x, float y, int pointer, int button) { ...


0

A Sprite is simply a data structure that contains information on how and where to draw a texture (i.e. position, color, texture handle, rotation, scale). Because of the way that OpenGL works, it is best to group or "batch" draw calls together to get the optimum performance. This grouping is why you will get an error if you try to draw to a Batch without ...


0

You can use a memory profiler like JProfiler(trial/paid) or JVmonitor(free) to take a snapshot of the heap when your program starts to eat up memory. These programs will at the very least tell you what type of object is eating up your memory. These of course will only work for the Desktop version of your app. Also ensure that you are using pooling ...


0

On Android Studio, on the heeader menu go to: View->Tool Windows->Gradle There you will see all you subprojects. open up the 'other', right click on the task 'dist' and click 'run'. This will create the distribution file in your HTML->build->dist folder. You can copy those file to your root folder (or link your root folder to this location)


0

A Sprite is a single sprite, whereas a SpriteBatch is a collection of multiple sprites, all drawn using the same settings.


1

According to this post you can draw a rotated quad. The line texture could be a 1x1 colored pixel. public static void drawLine(Batch batch, float x1, float y1, float x2, float y2, float lineWidth, TextureRegion lineTexture) { float xdif = x2-x1; float ydif = y2-y1; float l2 = xdif*xdif+ydif*ydif; float invl = (float)(1/Math.sqrt(l2)); //dif is ...


0

you could just move the transform.y up n number of times until the feet are on the ledge and forget the physics temporarily, i think it will work fine, you can always measure the distance between falling objects and the player in case collision fails during a transform translation. to make sure a collision occcurs..


0

According to this section in the AssetManager page. When Android pauses, then the managed libgdx elements, like Textures, get cleaned up an have to be reloaded when the app resumes. To do this, you call Texture.setAssetManager(manager); and then call update on the asset manager like you did when you first loaded. Secondly, Android apps have no guarantee ...


0

To expand on @user3068350's answer, something like this should work; public class MyGame extends Game { private Stage stage; private Texture myTexture; private TextureRegion myTextureRegion; private TextureRegionDrawable myTexRegionDrawable; private ImageButton button; @Override public void create() { myTexture = new ...


0

A drawable has information about its size and how to draw itself. It's used to determine size and position by ui components. Since you are using a texture, you can use a TextureRegionDrawable. Drawable drawable = new TextureRegionDrawable(new TextureRegion(playTexture); ImageButton playButton = new ImageButton(drawable);


1

I'm not going to go into details, but what you should be looking into is something like WinAMP's MilkDrop plugin presets and porting them to a shader. A good selection of example shaders (and how to write them) can be found at https://www.shadertoy.com/. These examples run on WebGL and use the GLSL language to render procedural content that is usually fast ...


4

The Android memory profilers that comes with the Android Developer Tools will allow you to figure out what is consuming your memory. It comes in three parts; Memory Monitor (this is used to find performance problems, so we can ignore this one for this particular problem). Tool Heap Viewer Allocation Tracker Using the Heap Viewer you can take snap-shots ...


0

It is because your "Ball b" and your ball's collider "Rectangle ball" know nothing about each other. When you update the ball's position with b.update() the rectangle ball stays put. I would make the Rectangle be a member variable of the Ball class and update its position every time the ball's position updates. i.e. if(goal.contains(b.getCollider())


1

The screen coords go from {-1,-1} to {1,1} but you are most likely feeding it {0,0} to {1,1} - hence the fact that only one-quarter of the screen gets rendered. So just to be clear - point {0,0} is not the top-left (or bottom-left, depending on your co-ordinate system) point; it's the center. This also explains the texture coord tranformation that you are ...


0

My guess is that you have a stray ! in your code. Remove the ! in: if (!Gdx.input.isTouched()) { This is making it so shootToward() is being called when the player is not touching the screen.


0

I would suggest having a look at this page and using a viewport to manage both cameras. Since you don't want scaling a ScreenViewport would be the way to go. https://github.com/libgdx/libgdx/wiki/Viewports // These would be the cameras you have set up which are following the players Camera playerOneCamera; Camera playerTwoCamera; ScreenViewport ...


0

The InputProcessor interface has touchDown() and touchUp() methods. Create a class that implements the InputProcessor interface and then give it to libgdx via MyInputProcessor inputProcessor = new MyInputProcessor(); Gdx.input.setInputProcessor(inputProcessor); I thought I should also note that if you are using scene2d and you want to react only when a ...


1

If you want to use sqlite with libGdx you can use opensource project gdx-sqlite . gdx-sqlite is a cross-platform Libgdx extension for SQLite database handling. The extension abstracts database handling to provide a unified method to handle database transacitons across multiple platforms while also adding SQLite support for desktop version of Libgdx ...


0

To move Camera in TiledMap bounds, OrthogonalTiledMapRenderer was used. I have also noticed it behaves unexpectedly: while Camera reaches map bounds, tiled map, like by inertia, moves some pixels too far (it depends on the velocity of the swipe). As a solution, on each Camera movement, Camera is forcibly put in map bounds. See putInMapBounds() method. To ...



Top 50 recent answers are included