我想创建一个Android赛车游戏,允许很多玩家互相比赛,玩家动画运动取决于用户在现实生活中的行进距离。开发这个游戏我用的是android studio和LibGdx。 检测用户运动我使用了步进检测器,其工作正常如下:
// Step Counter
SensorManager sManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sManager.registerListener(new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float steps = event.values[0];
textViewStepCounter.setText((int) steps + "");
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER),
SensorManager.SENSOR_DELAY_UI);
// Step Detector
sManager.registerListener(new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
// Time is in nanoseconds, convert to millis
timestamp = event.timestamp / 1000000;
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR),
SensorManager.SENSOR_DELAY_UI);
}
private void setupDetectorTimestampUpdaterThread() {
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
// textViewStepDetector.setText(DateUtils.getRelativeTimeSpanString(timestamp));
}
};
detectorTimeStampUpdaterThread = new Thread() {
@Override
public void run() {
while (isRunning) {
try {
Thread.sleep(5000);
handler.sendEmptyMessage(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
detectorTimeStampUpdaterThread.start();
现在我的问题是,如何在libgdx中使用此代码,是否有任何函数可以计算Libgdx中的用户步骤 谢谢