时间处理程序中的时间处理程序
Time Handler inside a time handler
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++;
}
我的问题是如何在此代码中创建延迟
if((grab_shell==1)&&(current_house!=7)&&(shell[current_house].getCurrentTileIndex()!=0))
{ grab_shell=2+shell[current_house].getCurrentTileIndex();
shell[current_house].setCurrentTileIndex(0);
}
此代码位于计时器处理程序中。我怎样才能做到这一点?请让我看看。
与其他条件相比,这部分代码有两个动作,这就是为什么我必须让这部分稍微延迟 1.4 秒
定时器处理程序可以嵌套。这意味着您可以在 timerhandler 中有一个定时器处理程序。您唯一需要确保的是取消注册您的处理程序以避免不必要的行为。我还假设您希望使用您指出的 if 语句创建计时器处理程序。
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++;
}
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++;
}
我的问题是如何在此代码中创建延迟
if((grab_shell==1)&&(current_house!=7)&&(shell[current_house].getCurrentTileIndex()!=0))
{ grab_shell=2+shell[current_house].getCurrentTileIndex();
shell[current_house].setCurrentTileIndex(0);
}
此代码位于计时器处理程序中。我怎样才能做到这一点?请让我看看。 与其他条件相比,这部分代码有两个动作,这就是为什么我必须让这部分稍微延迟 1.4 秒
定时器处理程序可以嵌套。这意味着您可以在 timerhandler 中有一个定时器处理程序。您唯一需要确保的是取消注册您的处理程序以避免不必要的行为。我还假设您希望使用您指出的 if 语句创建计时器处理程序。
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++;
}