I am working on a game which uses the accelerometer to move an object called "plane". I know how to add an accelerometer, but I can't get the plane to move.
package com.wyvern.pp.states;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.wyvern.pp.PPlane;
public class PlayState extends State{
private boolean peripheralAvailable;
private Texture walls;
private Texture bg;
private Texture plane;
public PlayState(GameStateManager gsm) {
super(gsm);
walls = new Texture("walls.png");
bg = new Texture("bg.png");
plane = new Texture("plane_left.png");
cam.setToOrtho(true);
peripheralAvailable = Gdx.input.isPeripheralAvailable(Input.Peripheral.Accelerometer);
}
@Override
protected void handleInput() {
}
@Override
public void update(float dt) {
handleInput();
float xRot;
if(peripheralAvailable) {
xRot = Gdx.input.getAccelerometerX();
}
}
@Override
public void render(SpriteBatch sb) {
sb.begin();
sb.draw(bg, 0, 0, PPlane.WIDTH, PPlane.HEIGHT);
sb.draw(walls, 0, 0);
sb.draw(plane, xRot, 15 ); // gives an error
sb.draw(walls, PPlane.WIDTH - walls.getWidth(), 0);
sb.end();
}
@Override
public void dispose() {
}
}
How do I get the plane to move left and right on the X axis?