擦除画布对象 [英] erase an object from canvas

查看:129
本文介绍了擦除画布对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个应用程序,我想精灵删除,一旦他们到达终点。我使用的ArrayList来处理在画布上我的精灵。我想精灵从画布和ArrayList中一旦他们的X - LT抹去自己; 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

这是我的code迄今为擦除命令:

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();
                }
            }


            }

它创造越来越多的精灵,我传递的最大INT,我把(5)。

it creates more and more sprites and i passes the max int that i put (5).

推荐答案

如果您使用的不是行 rockSprites.remove(精灵)而不是使用 rockSprites.remove(本)

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屋!

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