如何仅在纵向模式下设置libgdx动态壁纸的屏幕方向?

时间:2018-12-22 14:44:58

标签: android libgdx live-wallpaper

我正在用Libgdx创建一个Android动态壁纸,它只是屏幕上的一个圆圈,它具有随机的颜色和位置,并缓慢向上移动。问题是我只希望程序处于纵向模式,但是当我打开手机时,它将进入横向模式。

我已经尝试将清单文件的方向更改为protrait android:screenOrientation =“ Portrait”,然后放置 this.setRequestOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);在Android启动器类中,但没有任何作用

Android启动器类

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

动态壁纸课程

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);

  }   
}

核心动态壁纸课程

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) {}
}

是否可以这样做。要仅将动态墙纸的方向固定为

0 个答案:

没有答案