1
我想知道的位置從一個更新的差異另一個如何知道Andengine在manageupdate中的身體以前的位置?
相關代碼:
@Override
protected void onManagedUpdate(float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
Log.d("bar move", "fuel: "+ Float.toString(walkingFuel)) ;
if(counter==5) { // each time is to fast to percive difference?
Log.d("bar move", "previous x : "+ Float.toString(previousPosition.x)) ;
Log.d("bar move", "current x : "+ Float.toString(PlayerBody.getPosition().x)) ;
Log.d("bar move", "fuel consumed: "+ Float.toString(Math.abs(previousPosition.x - PlayerBody.getPosition().x) * 5));
walkingFuel += Math.abs(PlayerBody.getPosition().x - previousPosition.x ) * 5.0f;
previousPosition = PlayerBody.getPosition();
Log.d("bar move", "current fuel : "+ Float.toString(walkingFuel)) ;
counter=0;
}
counter++; }
我認爲每個manageupdate的性差異是低percive差異,這就是爲什麼在櫃檯上。任何如何,在每個maneageUpdate之前和現在都是相等的。
這裏有點我的日誌,使其更簡單
燃料:0.0
先前的x:6.8613663
當前x:6.8613663
燃油消耗:0.0
當前燃料:0.0
後期
燃料:0.0
先前的x:7.0288167
當前x:消耗7.0288167
燃料:0.0
當前燃料:0.0
所以,我做錯了這裏?如果是這樣,那麼做正確的方法是什麼?
它的工作,對於遲到的迴應感到抱歉 –
作爲補充,我想補充一點,更好的方法是不在每一幀中創建新的Vectro2對象。但在循環外部創建一個vertor並將其存儲在對象的專用字段中。然後,當您想要複製該值時,可以使用Vector2類的「set(Vector2 v)」方法。在這種情況下,它將複製值並且不會創建新對象。所以你的程序運行得更快。 – user1136881
它對速度真的沒什麼貢獻,它的差別很小。無論如何,我會嘗試。 –