I need to count user step in my game to move player character. My player should move while someone is walking, but after I use System.out.print on numstep its still zero. How can i count my step in Java and the LibGDX Framework?
public class PlayerBros extends Game {
public int step=0;
}
public class AndroidLauncher extends AndroidApplication implements SensorEventListener,StepListener {
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
accel = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
simpleStepDetector = new StepDetector();
simpleStepDetector.registerListener(this);
sensorManager.registerListener(AndroidLauncher.this, accel, SensorManager.SENSOR_DELAY_FASTEST);
config = new AndroidApplicationConfiguration();
playerBros=new PlayerBros();
numSteps = playerBros.step;
initialize(playerBros, config);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
simpleStepDetector.updateAccel(
event.timestamp, event.values[0], event.values[1], event.values[2]);
System.out.print("AndroidLauncher: "+numSteps);
}
}
@Override
public void step(long timeNs) {
numSteps++;
}
}
public class PlayScreen implements Screen {
private PlayerBros game;
public void handleInput(float dt){
player.b2body.applyLinearImpulse(new Vector2(game.step,y), player.b2body.getWorldCenter(), true);
hud.marioLabel.setText(" "+game.step);
System.out.print("PlayScreen: "+game.step);
}
public void update(float dt){
handleInput(dt);
}
}