首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AndEngine TimerHandler - onTimePassed

AndEngine TimerHandler - onTimePassed
EN

Stack Overflow用户
提问于 2015-02-04 17:38:44
回答 1查看 209关注 0票数 0

我正在使用AndEngine创建发射弹丸的物理模拟。当它模拟的时候,我想画出寓言的轨迹。为了做到这一点,我每秒钟根据弹丸(SPlayer)的位置画一个正方形。

代码语言:javascript
复制
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:

代码语言:javascript
复制
  @Override
public Engine onCreateEngine(final EngineOptions pEngineOptions) {
return new FixedStepEngine(pEngineOptions, 50);
}

问题是:

我不知道为什么调用onTimePassed的速度快于1秒间隔.It发生在几秒钟之后。

我读到的问题-- FixedStepEngine正在改变'onTimePassed‘被调用的间隔。如何修复?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-12 12:41:18

在我看来,您没有注销您的计时器处理程序,这会导致它们相互交叉。尝试取消注册pTimerHandler

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28327805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档