I am starting to develop Android games, and I am developing a small game. I encounter some difficulties with a motion sensor: an accelerometer.
This game is in landscape mode. I want my phone to lean to the right, my character also did the right thing. (same for left) And when I stop the character’s tilt, the game should stop moving.
But I don’t understand the operation of the accelerometer very well,
here is my code:
@Override public void onSensorChanged(SensorEvent event) { synchronized (this) { long penchement = (long) (event.values[1]- 0.5); if(penchement>0){ if(penchement>lastUpdate) lastUpdate=penchement; if(penchement>0.2){ booldroite=true; // boolean for going right boolgauche=false; // boolean for going left } if(lastUpdate-penchement<0.2) booldroite=false; } else{ if(penchement<lastUpdate) lastUpdate=penchement; if(penchement<-0.2){ boolgauche=true; booldroite=false; } if(lastUpdate+penchement>-0.2) boolgauche=false; } }
So, my code works (a bit), but my character movements are not smooth. Sometimes my phone tilts, but my characters do not move ...
Thank you in advance if you can help me.
android accelerometer sensor andengine
Alexandre Nicolas Dec 18 '12 at 15:04 2012-12-18 15:04
source share