LibGDX Particle Effect Color Resolution Different - libgdx

I hope to make a aurora looks like background with particle effect. Why the color effect seems so different at both desktop an real phone device view?
Desktop view
Phone view
I want a smooth color like desktop view in smartphone device too. How can i achieve that? Please provide me some guideline.
My android launcher class goes as below:
public class AndroidLauncher extends AndroidApplication implements Facebook230918 {
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.a = 8;
config.b = 8;
config.g = 8;
config.r = 8;
initialize(new MyGdxGame(this), config);
}

Related

Lwjgl3Application drawing perf degrades from 1.9.10 to 1.9.11

Hi I have a game that was using Lwjgl3Application with 1.9.10, after updating to 1.10.0 the drawing is noticeably worse on my 2014 macbook pro. You can tell the difference even when drawing a single texture. When texture are drawn, it looks like they are drawn in horizontal chunks, giving the illusion that drawing is lagging. The framerate via Gdx.graphics.getFramesPerSecond() is still ~60. On larger scenes, the weirdness in drawing is very apparent as large horizontal bands of artifacts going across the screen.
I used the project generator tool to make a scratch project to try and narrow it down, it looks like the degradation happens between 1.9.10 and 1.9.11.
In comparison, using LwjglApplication works just as well as before.
Below is the code, if running on a mac make sure to add the -XstartOnFirstThread VM arg to the desktop launcher otherwise it won't start.
public class DesktopLauncher {
public static void main (String[] arg) {
final Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
new Lwjgl3Application(new MyGdxGame(), config);
}
}
public class MyGdxGame extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
int posX, posY;
#Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
}
#Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, posX, posY);
batch.end();
// make texture move around a bit
posX++;
posY++;
if (posX >= Gdx.graphics.getWidth() - img.getWidth()) {
posX = 0;
posY = 0;
}
}
#Override
public void dispose () {
batch.dispose();
img.dispose();
}
}
Thanks

libgdx viewport fit different screens

I'm having a problem with fitting my game on different screens.
I declared a viewport width and height in my stage class.
public static final int VIEWPORT_WIDTH = 20;
public static final int VIEWPORT_HEIGHT = 30;
And i set up the camera
camera = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
camera.position.set(camera.viewportWidth/2, camera.viewportHeight/2, 0f);
And i set the screen width and height in desktop app to this
public static final int APP_WIDTH = 800;
public static final int APP_HEIGHT = 900;
On desktop everything looks fine but on my android device it looks stretched upwards. I read the documentation about viewports but how can I implement it here using these variables? I know similar questions have been asked but I would like to know viewports can be implemented using these specific variables, that way I might understand it better.
You probably want to use an ExtendViewport. This extends the world 1 way to fill the entire screen.
your code would look something like this:
private Viewport viewport;
private Camera camera;
public void create() {
camera = new OrthographicCamera();
viewport = new ExtendViewport(VIEWPORT_WIDTH , VIEWPORT_HEIGHT, camera);
}
public void resize(int width, int height) {
viewport.update(width, height);
}
Read more here: https://github.com/libgdx/libgdx/wiki/Viewports#extendviewport

How to detect if the device is an Amazon kindle in libgdx

I want to do something if the device that is running my libgdx app is an Amazon kindle. How do I detect this. I found how to do not using libgdx using android.os.Build.MANUFACTURER, but it doesn't work in a libgdx game. So how do I detect if the device is an Amazon kindle in libgdx?
Thanks in advance!
Add two constructors and attributes to your core project class:
public String model;
public String manufacturer;
public MyGame(){ } //for web, ios and desktop
public MyGame(String manufacturer, String model){ //for android
this.manufacturer = manufacturer;
this.model = model;
}
In the AndroidLauncher of your android project you can pass the values Build.MANUFACTURER and Build.MODEL to your class constructor:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new MyGame(Build.MANUFACTURER,Build.MODEL), config);
}
You can have a look in the device specifications of amazon with value belongs to the kindle.

Libgdx android back button exit app

I'm using libgdx in my game and I want to catch android back button.
I want this scenario:
I have three screens: Screen1, Screen2 and Screen3. When I'm on Screen3 and I press back button on android I want to open Screen2 screen, but in my case all app exit (Closes all sceens 1,2 and 3). I'm using this code:
#Override
public void show() {
backButtonPressed = false;
Gdx.input.setCatchBackKey(true);
}
#Override
public void hide() {
Gdx.input.setCatchBackKey(false);
}
#Override
public void render(float deltaTime) {
if (Gdx.input.isKeyPressed(Keys.BACK) && !backButtonPressed){
ScreenTransition transition = ScreenTransitionFade.init(0.5f);// init(0.5f, ScreenTransitionSlice.UP_DOWN, 10, Interpolation.pow5Out);
game.setScreen(new Screen2(), transition);
backButtonPressed = true;
}
}
The same code in Screen3 and Screen2 (new Screen1() and new Screen2())
Thanks
See catchbackkey not working (libgdx) Android for the solution - the short version is that you should be hooking isKeyUp

My Libgdx game slow when integrated Admob

I am a new game developing with libgdx. I have a problem with Admob ads. When I call "adView.loadAd(adRequest);" my game is slowl, when I start game, FPS ~ 60 , when I call adView.loadAd(adRequest) my game is slowly FPS ~ 30.
Here is my
public class MainActivity extends AndroidApplication implements IActivityRequestHandler {
protected AdView adView;
AdRequest adRequest;
private final int SHOW_ADS = 1;
private final int HIDE_ADS = 0;
protected Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SHOW_ADS: {
System.out.println("SHOW ADVIEW");
adView.setVisibility(View.VISIBLE);
break;
}
case HIDE_ADS: {
adView.setVisibility(View.GONE);
break;
}
}
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the layout
RelativeLayout layout = new RelativeLayout(this);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
View gameView = initializeForView(new MyGdxGame(this), false);
// Create and setup the AdMob view`enter code here`
adView = new AdView(this, AdSize.BANNER, "XXXXXX"); // Put in your
// secret key
// here
adRequest = new AdRequest();
adView.loadAd(adRequest);
// adView.loadAd(new AdRequest());
// Add the libgdx view
layout.addView(gameView);
// Add the AdMob view
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(adView, adParams);
// Hook it all up
setContentView(layout);
}
// This is the callback that posts a message for the handler
#Override
public void showAds(boolean show) {
handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
}
}
I read topic Using interstitials from Admob in a Libgdx game for Android, it's slow when dismissing it
but not solution
Please help me if you have a solution.
This is a known issue and at the moment you cant change it.
Post at the libgdx Forum
It has nothing todo with your code. I think