精灵生成加倍并导致强制关闭

发布于 2024-11-09 15:55:25 字数 1590 浏览 0 评论 0原文

现在我有在不同时间生成的精灵。我想要弄清楚的是,为什么经过这么长时间之后,它突然开始产生越来越多的僵尸2。就像它从一对产卵变成了 3 比 6 甚至更多同时产卵。我认为我的 postDelayed 会很好地处理这个问题,并使它们以恒定的速度而不是增加。我不确定这是否是导致它的原因,但似乎在它产生一堆僵尸2的时候它会强制关闭。 (这可能与我将应用程序设置为 1.5 的事实有关吗?是否应该将其设置为更高的版本,就像我看到其他人所做的那样?) 任何帮助将不胜感激。这是一些运行生成的代码。

    @Override
    public void run() {
        long  elapsed;
        elapsed=System.currentTimeMillis()-startTime;


        if (elapsed> 5000)
        {
            normZombie.add(createSprite(R.drawable.zombie1));
            normZomb.postDelayed(this, 3000);
        }
        else if (elapsed >15000)
        {
            normZombie.add(createSprite(R.drawable.zombie1));
            normZomb.postDelayed(this, 1500);
        }
        else
        {
            normZombie.add(createSprite(R.drawable.zombie1));
            normZomb.postDelayed(this, 1000);
        }

        if (elapsed >= 10000)
        {
            fastZombie.add(createZombie2(R.drawable.zombie2));
            fastZomb.postDelayed(this, 10000);
        }
//      else if(elapsed >25000)
//      {
//          fastZombie.add(createZombie2(R.drawable.zombie2));
//          fastZomb.postDelayed(this, 5000);
//      }
//      else if(elapsed >40000)
//      {
//          fastZombie.add(createZombie2(R.drawable.zombie2));
//          fastZomb.postDelayed(this, 3000);
//      }


    }

我删除了被注释掉的部分,因为我认为它有一部分。我确实认为它加速了它。 if - else 都是用来设置它的,所以在一段时间后生成率会增加。

谢谢

编辑:好的,通过进一步的尝试,我相信 postDelayeds 是如何相互递增的。我只是拥有所有内容,但只有其中一个被注释掉,并且它重复了很多秒,并且连续正确地执行了它。当我将其中一个发布在一起时(不包括 if if-elses ),它们自己开始变得越来越快。知道为什么吗?

Right now I have sprites that spawn at different times. What I'm trying to figure out is why after so much time passes it suddenly starts spawning the zombie2 in larger and larger amounts. Like it goes from a couple spawning to like 3 than 6 and more spawning at the exact same time. I thought my postDelayed would have handled that just fine and make them at a constant rate not incrementing. I'm not sure whether this is what is causing it or not but it seems that around the time it spawns a bunch of the zombie2's it force closes. (Could this possibly be related to the fact that I have the app set for 1.5? Should it be set to something higher like I have seen some others do?)
Any help would be appreciated. Here is some code that is running the spawns.

    @Override
    public void run() {
        long  elapsed;
        elapsed=System.currentTimeMillis()-startTime;


        if (elapsed> 5000)
        {
            normZombie.add(createSprite(R.drawable.zombie1));
            normZomb.postDelayed(this, 3000);
        }
        else if (elapsed >15000)
        {
            normZombie.add(createSprite(R.drawable.zombie1));
            normZomb.postDelayed(this, 1500);
        }
        else
        {
            normZombie.add(createSprite(R.drawable.zombie1));
            normZomb.postDelayed(this, 1000);
        }

        if (elapsed >= 10000)
        {
            fastZombie.add(createZombie2(R.drawable.zombie2));
            fastZomb.postDelayed(this, 10000);
        }
//      else if(elapsed >25000)
//      {
//          fastZombie.add(createZombie2(R.drawable.zombie2));
//          fastZomb.postDelayed(this, 5000);
//      }
//      else if(elapsed >40000)
//      {
//          fastZombie.add(createZombie2(R.drawable.zombie2));
//          fastZomb.postDelayed(this, 3000);
//      }


    }

The section that is commented out I took out because I thought it had a part in it. I do think it accelerates it though. The if - elses are all there to set it up so after a certain amount of time the spawn rate increases.

Thanks

EDIT: Ok so from further toying around with it I believe that some how the postDelayeds are incrementing off of eachother. I simply had everything but just one of them commented out and it repeated as it should ever so many seconds and it did it correctly continuously. When I have one of each posted together (not including the if if-elses ) the begin to happen faster and faster on their own. Any idea why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅沫记忆 2024-11-16 15:55:25

所以如果其他人也有这个问题......我知道它是什么。我需要两个单独的可运行程序,因为每次调用 1 时它们都会相互递增。这是代码现在的样子。

Runnable norm = new Runnable(){

            @Override
            public void run() {
                normZombie.add(createSprite(R.drawable.zombie1));
                normZomb.postDelayed(this, 3000);

            }

           };

                 Runnable fast = new Runnable(){

                    @Override
                    public void run() {

                        fastZombie.add(createZombie2(R.drawable.zombie2));
                        fastZomb.postDelayed(this, 10000);
                    }

                };
                norm.run();
                fast.run();

像这样效果很好。

So if anyone else has this problem... I figured out what it was. I needed two separate runnable because some how they were incrementing off of eachother each time 1 was called. Here is what the code looks like now.

Runnable norm = new Runnable(){

            @Override
            public void run() {
                normZombie.add(createSprite(R.drawable.zombie1));
                normZomb.postDelayed(this, 3000);

            }

           };

                 Runnable fast = new Runnable(){

                    @Override
                    public void run() {

                        fastZombie.add(createZombie2(R.drawable.zombie2));
                        fastZomb.postDelayed(this, 10000);
                    }

                };
                norm.run();
                fast.run();

It works well like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文