Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[SOLVED] Help with erasing a Rect()
-
Look at python lists namely the part on
list.remove
Also as @JonB has stated remove global variables where they are not required
Something to consider as wellif not self.player.intersects(cells): ellipse(*self.player) if self.player.intersects(cells): self.newpsize=self.psize+10 self.psize=self.newpsize ellipse(*self.player)
can become
if self.player.intersects(cells): self.newpsize=self.psize+10 self.psize=self.newpsize ellipse(*self.player)
-
OK, I removed the useless global variables... However, its not a list - it's a Rect(). Maybe you could help me with making it a list instead. If it can't be erased.
-
self.particles
is a list. if an item in it intersects then remove it. You are already checking if items intersect, tweaking the code a bit will allow you to remove it. -
That's what I need help with... @Cethric
Sorry if I'm being a pain.
-
In the iteration of
self.particles
>for p in self.particles
, there is a check for intersectionif self.player.intersects(cells):
wherecells = p.cells
. If this check isTrue
then removep
from the listself.particles
-
So from my code, I just have to fun a way to remove p.cells, or do I have to check something else first? @Cethric
-
This would be a whole lot easier if there was a repo where pull requests could be submitted to fix the code. Everyone needs a common codebase to be fixing rather then English prose corrections to Python code.
-
self.particles
is a list and the variablep
is an item from the list. the functionlist.remove
removes an item from the list. Hence in your code if a cell intersects the remove it from the list.
ieif self.player.intersects(cells): ... self.particles.remove(p)
I apologise in advanced if I come across being annoyed it is not how I intend to come across.
-
No, its fine. Also, thanks a bunch!
-
A different suggestion: try using layers. The advantage of layers is that most of the "hard work" is done for you, such as adding and removing objects, positioning objects relative to their parent, rendering them properly, etc. You also don't need to keep track of all objects manually in a list somewhere, instead you add them as sublayers of another layer, and they will be drawn automatically.
Consider making a backup copy of your script before changing it to use layers, you might run into problems and want to look at your original code.