Where to find a simple example to move a ball using accelerometer(Andengine) . I make that using onKeyDown events.
int x=20; iny y=10;
//ballSprite.setPostion(x,y); Eg: when pressed leftKey
x=x-5开发者_C百科;
when Pressed Up key
y=y+5;
The same thing , how to make using accelerometer.. Any samples ?
Specific to AndEngine... download the AndEngineExamples and check out the source for the PhysicsExample. It uses the accelerometer to adjust the gravity of the physics world.
Essentially, all you do is override onAccelerometerChanged to move the ball using the AccelerometerData.
You may find the following useful;
public class AccelerometerScreen extends BaseGameActivity implements IAccelerometerListener, IOnAreaTouchListener{
private static final int CAMERA_WIDTH = 480;
private static final int CAMERA_HEIGHT = 720;
@Override
public void onLoadResources() {
this.enableAccelerometerSensor(this);
this.mEngine.getTextureManager().loadTextures(mTexture);
}
@Override
public Scene onLoadScene() {
mEngine.registerUpdateHandler(new FPSLogger());
}
@Override
public void onAccelerometerChanged(AccelerometerData pAccelerometerData) {
accellerometerSpeedX = (int)pAccelerometerData.getX();
// accellerometerSpeedY = (int)pAccelerometerData.getY();
Log.v("Accelerometer X Y Z: ", ""+pAccelerometerData);
// from this accelerometer data u can set ur sprite.
}
}
精彩评论