在哪裏可以找到使用加速度計(Andengine)移動球的簡單示例。我使用onKeyDown事件。使用加速度計移動球(簡單示例)
int x = 20; iny y = 10;
//ballSprite.setPostion(x,y); 例如:按下時左鍵
x = x-5;
向上壓時鍵
Y = Y + 5;
同樣的事情,如何使用加速度計..任何樣品?
在哪裏可以找到使用加速度計(Andengine)移動球的簡單示例。我使用onKeyDown事件。使用加速度計移動球(簡單示例)
int x = 20; iny y = 10;
//ballSprite.setPostion(x,y); 例如:按下時左鍵
x = x-5;
向上壓時鍵
Y = Y + 5;
同樣的事情,如何使用加速度計..任何樣品?
你可能會發現以下有用的;
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.
}
}
特定於AndEngine ...下載AndEngineExamples並查看PhysicsExample的源代碼。它使用加速度計來調整物理世界的重力。
本質上,你所做的就是覆蓋onCelelemeterChanged以使用AccelerometerData移動球。
對不起,但你有沒有試過去搜索它?我使用了3個詞語進行搜索,並提出了以下建議:http://blog.androgames.net/85/android-accelerometer-tutorial/,因爲您應該考慮:並非所有內容都「簡單」,因此使用加速度計需要一些時間瞭解和一些數學技能。 「簡單」也很主觀。嘗試教程,並將其與andengine結合...問你是否有一個特定的問題... – WarrenFaith
好評。這是真的 – PedroAGSantos
http://www.robertpenner.com/easing/penner_chapter7_tweening.pdf預訂補間所有方面的章節。詳細解釋數學。 – QuentinUK