从画布上擦除对象 [英] erase an object from canvas
问题描述
我正在尝试开发一个应用程序,我希望精灵在到达结束时将其擦除.我正在使用 arraylist 在画布上处理我的精灵.我希望精灵一旦 x<0(在画布之外)就从画布和数组列表中擦除自己,请尽快帮助我.谢谢
I am trying to develop an application and i want the sprites to erase once they reach the end. I am using arraylist to handle my sprites on a canvas. I want the sprites to erase themselves from the canvas and from the arraylist once their x<0 (outside of the canvas) Please help me asap. Thanks
这是我迄今为止的擦除命令代码:
This is my code so far for the erase command:
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();
}
}
}
它创建了越来越多的精灵,并且我传递了我放置的最大整数 (5).
it creates more and more sprites and i passes the max int that i put (5).
推荐答案
您是否应该使用 rockSprites.remove(sprite)
而不是使用 rockSprites.remove(this)代码>?
Should you not be using the line rockSprites.remove(sprite)
rather than using rockSprites.remove(this)
?
因为它没有被列出,我假设你的渲染阶段实际上使用了 rockSprites
ArrayList(?) 来确定应该在画布上放置哪些摇滚精灵?
Since it's not listed, I am going to assume that your render phase actually uses the rockSprites
ArrayList(?) to determine what rock sprites should be put on the canvas?
这篇关于从画布上擦除对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!