Hyper Speed会冻结游戏吗? [英] Hyper Speed freezes the game?

查看:154
本文介绍了Hyper Speed会冻结游戏吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太了解这将如何工作和日历,这导致游戏冻结,但它是游戏的一个重要部分,不能被砍掉。相信我这是错误的地方,这是需要改变的地方。我也会给你我的进口。如果你确实需要更多代码,我会修改问题。









I don't know much about how this would work and Calendar, and this causes the game to freeze, but it is an essential part of the game and can not be chopped off. Trust me this is where the error is and this is what needs to be changed. I will also give you my imports. If you do need some more code just ask and I will revise the question.




if(hypspd == true && e.getKeyCode() == 16) {
          Calendar stop = Calendar.getInstance();
          Calendar start = Calendar.getInstance();
          long lstart = start.getTimeInMillis();
          long lstop = stop.getTimeInMillis();
          int istart = (int) (long) lstart;
          int istop = (int) (long) lstop;
          long elapsed = ((istop - istart) / 1000);
          istart = (int)start.getTimeInMillis();
          while(elapsed <= 10)
          {
          speed = 10;
                  t.setText("Score==>" + score + "         HYPER SPEED!!!!                           Speed: " + speed);
                  istop = (int)stop.getTimeInMillis();
          }
                  if(elapsed == 10)
                  {
                    speed = 50;
                    elapsed = 0;
                    elapsed = (istop - istart) / 1000;
                  t.setText("Score==>" + score + "                                                   Speed: " + speed);
                  }













提前致谢!







Thanks in advance!

推荐答案

我建​​议你做一些改变,这可能会有所帮助,就是不要使用Calendar,它需要做很多不必要的工作。如:

A couple changes I recommend you make, that might help, are to not use Calendar, it requires to much unnecessary work. As:
Calendar stop = Calendar.getInstance();
Calendar start = Calendar.getInstance();
long lstart = start.getTimeInMillis();
long lstop = stop.getTimeInMillis();
int istart = (int) (long) lstart;
int istop = (int) (long) lstop;
long elapsed = ((istop - istart) / 1000);
istart = (int)start.getTimeInMillis();



可以更容易地使用java.lang.System中。参见示例:


can be done much easier using java.lang.System. See example:

long startTime = System.currentTimeMillis();
long stopTime = System.currentTimeMillis();
long elapsedTime = (stopTime - startTime) / 1000;



看看我的意思?



另外,你不需要像下面那样使用密钥编号:


See what I mean?

Another thing, is you do not need to use the key number like you did below:

if(hypspd == true && e.getKeyCode() == 16) { }



相反,请利用java.awt.event.KeyEvent。我还清理了代码,以便更容易阅读本例。


Instead, take advantage of java.awt.event.KeyEvent. I also cleaned the code up, to make it easier to read for this example.

int key = e.getKeyCode();
if (hypspd == true && key == KeyEvent.VK_SHIFT) {}





基本上,使用KeyEvent,您可以更直观地表示您选择的是什么键,而不是尝试使用实际的KeyCode。



我不确定这是否能解决游戏冻结的问题,如果不让我知道,我会进一步调查。另外,请让我知道这些变化是否对您有所帮助!



干杯!



Basically, using the KeyEvent, you can get a more visual representation of what key you are choosing, instead of trying to use the actual KeyCode.

I am not sure if this will fix the problem with your game freezing, if not let me know, and I will investigate further. Also, please let me know if the changes help you at all!

Cheers!


这篇关于Hyper Speed会冻结游戏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆