我正在使用AndEngine创建发射弹丸的物理模拟。当它模拟的时候,我想画出寓言的轨迹。为了做到这一点,我每秒钟根据弹丸(SPlayer)的位置画一个正方形。
time_handler=new TimerHandler(1, true, new ITimerCallback() {
@Override
public void onTimePassed(TimerHandler pTimerHandler) {
if(simulationOn){ // every 1 second if the simulation is on
int px=(int)sPlayer.getSceneCenterCoordinates()[0];
int py=(int)sPlayer.getSceneCenterCoordinates()[1];
parabola_point=new Rectangle(px, py,4, 4,getVertexBufferObjectManager());
parabola_point.setColor(Color.WHITE);
if(!highest_point_found){ //if highest point not found, check it
float difY = (float) Math.floor(Math.abs(body.getLinearVelocity().y)) ;
if(Float.compare(0f, difY) == 0){ // if it is the highest point
highest_point_found=true;
drawPointText(); //draw the positions on the scene
parabola_point=new Rectangle(px, py,16, 16,getVertexBufferObjectManager());
parabola_point.setColor(Color.RED); // paint this point red
}
}
parabola.add(parabola_point);
scene.attachChild(parabola_point);
}
// pTimerHandler.reset();
}
});我使用的是FixedStepEngine:
@Override
public Engine onCreateEngine(final EngineOptions pEngineOptions) {
return new FixedStepEngine(pEngineOptions, 50);
}问题是:
我不知道为什么调用onTimePassed的速度快于1秒间隔.It发生在几秒钟之后。
我读到的问题-- FixedStepEngine正在改变'onTimePassed‘被调用的间隔。如何修复?
发布于 2015-02-12 12:41:18
在我看来,您没有注销您的计时器处理程序,这会导致它们相互交叉。尝试取消注册pTimerHandler
https://stackoverflow.com/questions/28327805
复制相似问题