简体   繁体   English

如何知道身体在Andengine的manageupdate中的先前位置?

[英]How to know the previous position of body in manageupdate in Andengine?

I wanted to know the difference of position from one update to another 我想知道从一次更新到另一次更新的位置差异

Relevant code: 相关代码:

 @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++; }

I thought that the diference from each manageupdate was to low to percive difference, thats why the counter. 我认为与每个manageupdate的差异都是很小的差异,这就是计数器的原因。 Any how, in each maneageUpdate both previous and current are equal. 无论如何,在每个maneageUpdate中,先前和当前都是相等的。

Here is a bit of my log to make it simpler 这是我的一些日志,使其更简单

fuel: 0.0 燃油:0.0

previous x : 6.8613663 前一个x:6.8613663

current x : 6.8613663 当前x:6.8613663

fuel consumed: 0.0 耗油量:0.0

current fuel : 0.0 当前燃油:0.0

Later 后来

fuel: 0.0 燃油:0.0

previous x : 7.0288167 前一个x:7.0288167

current x : 7.0288167 当前x:7.0288167

fuel consumed: 0.0 耗油量:0.0

current fuel : 0.0 当前燃油:0.0

So, I did something wrong here? 所以,我在这里做错了吗? If so, whats the right way of doing it? 如果是这样,正确的做法是什么?

previousPosition = PlayerBody.getPosition();

Probably here you just copy the reference to the object but not the value. 在这里,您可能只是将引用复制到对象,而不是复制值。 You need to copy the value. 您需要复制值。 May be something like this: 可能是这样的:

previousPosition = new Vector2(PlayerBody.getPosition().x, PlayerBody.getPosition().y);

I don't remember what type you should use for storing position in andEngine, so change the type to the type of "previousPosition". 我不记得应该使用什么类型在andEngine中存储位置,因此将类型更改为“ previousPosition”的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM