1

I am creating an Android Live Wallpaper with Libgdx , It is just a circle on the screen which gets a random color and position and it slowly moves up . The issue is I want the program only in portrait mode but when i turn my phone it goes into landscape mode.

I have already tried changing the manifest file orientation to protrait android:screenOrientation="Portrait", and placing this.setRequestOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); in Android Launcher Class but nothing is working

Android Launcher Class

public class AndroidLauncher extends AndroidApplication {
@Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    initialize(new CoreLWP(), config);
     }
    }

Live Wallpaper class

public class LiveWallpaper  extends AndroidLiveWallpaperService {

public CoreLWP wallpaper;

@Override
public void onCreateApplication () {
super.onCreateApplication();

final AndroidApplicationConfiguration config = new    AndroidApplicationConfiguration();

this.wallpaper = new CoreLWP();
initialize(this.wallpaper, config);

  }   
}

Core Live Wallpaper class

public class CoreLWP extends ApplicationAdapter implements ApplicationListener, AndroidWallpaperListener {


private ShapeRenderer ball;
private float x,y;
private Random random;

private float r,g,b;

@Override
public void create () {
ball = new ShapeRenderer();
random = new Random();

//generating random position
x = random.nextInt(Gdx.graphics.getWidth());
y = random.nextInt(Gdx.graphics.getHeight());

 //generating random rgb values
 r = getFloatRandomNum(0, 1) ;
 g = getFloatRandomNum(0, 1) ;
 b = getFloatRandomNum(0, 1) ;
 }

   @Override
    public void render () {

//setting the background
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

//updating x and y position
x = x + 0.5f;
y = y + 0.6f;

ball.begin(ShapeRenderer.ShapeType.Filled);
ball.setColor(r,g,b,1);
ball.circle(x,y,100);
ball.end();

}

//returns a random float number between a range
private float getFloatRandomNum(float min, float max) {
float random = min + new Random().nextFloat() * (max - min);
return random;
}

@Override
public void dispose () {
ball.dispose();
}

@Override
public void offsetChange(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {}

@Override
public void previewStateChange(boolean isPreview) {}

@Override
public void iconDropped(int x, int y) {}
}

Is it possible to do so . To fix the orientation only to portrait for the live wallpaper

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 1
    You can't do this. The launcher app in Android decides the dimensions of the wallpaper, and you have no control over it. As a workaround, what you could do is in `resize()`, if the width is greater than the height, rotate your camera 90 degrees. – Tenfour04 Dec 22 '18 at 15:08
  • So I have to setup camera and view port in order the get the desired effect. – InSearchOfCode Dec 24 '18 at 13:53
  • You don't need a Viewport. That will actually make it more convoluted to have a rotated camera. – Tenfour04 Dec 24 '18 at 14:37
  • yes, View port will make thing more convoluted . – InSearchOfCode Dec 26 '18 at 03:57

0 Answers0