Libgdx shader changes texture

In my libgdx project I use a custom shader to create different color variations of a single grayscale character. I have a class “Shader” which holds static String variables for the vertex and fragment shaders. For each person I basically create a new shader, by replacing strings in the fragment shader string. For some reason, … Continue reading “Libgdx shader changes texture”

LibGdx Box2d collison not matching up with sprite

I am making a game as a project for a college class. when my main character (the tree) hits the ground, it stops short of the ground screenshot 1 and when the player lands on the little platform that gap is even bigger screenshot 2 my code for creating the body of the character and … Continue reading “LibGdx Box2d collison not matching up with sprite”

How to record a longer touch for a higher jump on libgdx

So in my game I want to have it so the longer someone holds down on the screen the higher my character jumps. However I don’t know how to check if someone is holding down on the screen. My current attempt is to do this: And run it every frame in the update method public … Continue reading “How to record a longer touch for a higher jump on libgdx”

Access rays cast by Box2D Lights

I am currently developing a game with the Box2D lights library and LibGDX. Everything is currently fine, however, I’m having difficulty accessing the rays from the ConeLight. I wish to stop rendering objects if they are not in the ray of the light. Is there any way to access the rays the library is casting … Continue reading “Access rays cast by Box2D Lights”

Libgdx Array<> how to get last item?

I want to change Y position of “bucket”, when camera Y position is higher than “last created bucket” Y position: There is my code in “create()” method buckets = new Array<Bucket>(); for(int i=1;i<BUCKET_COUNT;i++){ buckets.add(new Bucket(world,(rand.nextInt((int)W)-45)/PPM,BUCKET_MARGIN*i/PPM)); } And I am doing like this in “render()” method: for(Bucket bucket : buckets){ if(cam.position.y > buckets.peek().getBody().getPosition().y){ bucket.repos(rand.nextInt((int)W)/PPM,buckets.size+BUCKET_MARGIN/PPM); } } … Continue reading “Libgdx Array<> how to get last item?”

Box2d contact listener collision

I am trying to realize one way platform using Box2d. This is my code: public void preSolve(Contact contact, Manifold oldManifold) { Fixture platform = null; Fixture ranger = null; Fixture fa = contact.getFixtureA(); Fixture fb = contact.getFixtureB(); if (BodyUtils.isPlatform(fa.getBody()) && BodyUtils.isRanger(fb.getBody())) { platform = fa; ranger = fb; } else if (BodyUtils.isPlatform(fb.getBody()) && BodyUtils.isRanger(fa.getBody())) { … Continue reading “Box2d contact listener collision”

Switch screens (libgdx) – Game class implementing ApplicationListener

We are working on a game with libgdx and we want to be able to switch screens. I have made a GameOverScreen, which implements Screen: public class GameOverScreen implements Screen { } My problem is that i don’t know how to set the screen in my main class. Most of the examples i have looked … Continue reading “Switch screens (libgdx) – Game class implementing ApplicationListener”

Tween object array elements to one corner on touch-LibGdx

In my game,I have array of coins appearing on a particular action.Once I touch the coins,coins have to move off smoothly(like flying) to one corner of the screen,one by one. I am creating and drawing coin array like this: private Coin coins[] = new Coin[10];//coin array for(int i=0;i<coins.length;i++) { coins[i]=objectFactory.createCoin();//creating object array of coins } … Continue reading “Tween object array elements to one corner on touch-LibGdx”

Admob ad not visible (Using LibGDX)

I followed the tutorials both here: https://developers.google.com/android/reference/com/google/android/gms/ads/AdView And here: https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx Everything looks like it should show up, but when I launch my app (both on my emulator and an actual device) no ads show up. Here is my code: import android.os.Bundle; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.LinearLayout; import android.widget.RelativeLayout; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; … Continue reading “Admob ad not visible (Using LibGDX)”