从画布中删除对象

时间:2011-11-03 03:01:40

标签: android canvas arraylist handle erase

我正在尝试开发一个应用程序,我希望精灵在它们到达结束时擦除。我正在使用arraylist在画布上处理我的精灵。我希望精灵从画布和arraylist中删除自己的x< 0(画布之外)请尽快帮助我。谢谢

这是我目前为止擦除命令的代码:

for(Sprite sprite : rockSprites){

            sprite.x -=10;
            if (Rect.intersects(sprite.dst, die))
            {
                rockSprites.remove(this);

                currentAmountOfSprites--;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }


            }

它创建了越来越多的精灵,我传递了我放入的最大int(5)。

1 个答案:

答案 0 :(得分:1)

您是否应该使用rockSprites.remove(sprite)行而非使用rockSprites.remove(this)

由于它没有列出,我假设你的渲染阶段实际上使用rockSprites ArrayList(?)来确定应该在画布上放置什么样的岩石精灵?