Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Andengine 时间处理程序中的时间处理程序_Andengine - Fatal编程技术网

Andengine 时间处理程序中的时间处理程序

Andengine 时间处理程序中的时间处理程序,andengine,Andengine,我的问题是如何在代码中创建延迟 TimerHandler timer = new TimerHandler(.7f, true, new ITimerCallback() { private int grab_shell=0; private int loop_count=0; public void onTimePassed(TimerHandler pTimerHa

我的问题是如何在代码中创建延迟

 TimerHandler timer =  new TimerHandler(.7f, true,  new ITimerCallback() {
                    private int grab_shell=0;
                    private int loop_count=0;

                    public void onTimePassed(TimerHandler pTimerHandler) {

                        if ((shell[0].getCurrentTileIndex()>0)&&(loop_count==0))
                        {
                            grab_shell=shell[0].getCurrentTileIndex();
                            shell[0].setCurrentTileIndex(0);
                        }
                        if(grab_shell>0)
                        {   
                            current_house++;
                            if(current_house==15)
                            {
                                current_house=0;
                            }
                            if((grab_shell==1)&&(current_house!=7)&&(shell[current_house].getCurrentTileIndex()!=0))
                            {

                                    grab_shell=2+shell[current_house].getCurrentTileIndex();
                                    shell[current_house].setCurrentTileIndex(0);

                                }
                            }

                            else if ((grab_shell==1)&&(current_house!=7)&&(shell[current_house].getCurrentTileIndex()==0))
                            {
                                shell[7].setCurrentTileIndex(shell[current_house].getCurrentTileIndex()+1);
                                shell[current_house].setCurrentTileIndex(0);
                            }
                            shell[current_house].setCurrentTileIndex(shell[current_house].getCurrentTileIndex()+1);
                            grab_shell--;
                        }

                        if(grab_shell==0)
                        {
                        unregisterUpdateHandler(pTimerHandler);
                        }
                        loop_count++;
                        }
此代码位于timerhandler中。我该怎么做?请给我看看。
与其他条件相比,这部分代码有两个动作,这就是为什么我必须使这部分稍微延迟1.4秒的原因。这意味着您可以在timerhandler中有一个计时器处理程序。您需要确保的唯一一件事是取消注册处理程序,以避免不必要的行为。我还假设您希望使用您指出的if语句创建计时器处理程序

    if((grab_shell==1)&&(current_house!=7)&&(shell[current_house].getCurrentTileIndex()!=0))
       {        grab_shell=2+shell[current_house].getCurrentTileIndex();
                                    shell[current_house].setCurrentTileIndex(0);
                            }

谢谢你的回答。这真符合我的想法。
TimerHandler timer =  new TimerHandler(.7f, true,  new ITimerCallback() {
                private int grab_shell=0;
                private int loop_count=0;

                public void onTimePassed(TimerHandler pTimerHandler) {

                    if ((shell[0].getCurrentTileIndex()>0)&&(loop_count==0))
                    {
                        grab_shell=shell[0].getCurrentTileIndex();
                        shell[0].setCurrentTileIndex(0);
                    }
                    if(grab_shell>0)
                    {   
                        current_house++;
                        if(current_house==15)
                        {
                            current_house=0;
                        }
                        if((grab_shell==1)&&(current_house!=7)&&(shell[current_house].getCurrentTileIndex()!=0))
                        {
                    //here
                    TimerHandler timer =  new TimerHandler(1.4f, true,  new ITimerCallback() {

                    @Override
                    public void onTimePassed(TimerHandler pTimerHandler) {
                    grab_shell=2+shell[current_house].getCurrentTileIndex();
                    shell[current_house].setCurrentTileIndex(0);
                   //unregister timer handler

                    }

                 });

                            }
                        }

                        else if ((grab_shell==1)&&(current_house!=7)&&(shell[current_house].getCurrentTileIndex()==0))
                        {
                            shell[7].setCurrentTileIndex(shell[current_house].getCurrentTileIndex()+1);
                            shell[current_house].setCurrentTileIndex(0);
                        }
                        shell[current_house].setCurrentTileIndex(shell[current_house].getCurrentTileIndex()+1);
                        grab_shell--;
                    }

                    if(grab_shell==0)
                    {
                    unregisterUpdateHandler(pTimerHandler);
                    }
                    loop_count++;
                    }