November 2011
Beginner
196 pages
5h 3m
English
To incorporate sensor data into the logic of a game and its updates, you need to pass the data into the game’s View class. First add this to the MainActivity class:
GameView mGameView;
You must also add the code shown in Listing 3-19 to the onCreate() method:
Listing 3-19. GameView Instance
mGameView = new GameView(this);
setContentView(mGameView);
You now have a GameView instance from which you can call various methods. Next, in GameView, you need to add a new function to which you pass your orientation data to. Listing 3-20 shows the call to add within onSensorChanged().
Listing 3-20. Sending Sensor Data
@Override
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){ ...Read now
Unlock full access