Erase a rectangle

Hey so can I erase a shape after drawing it? For example I want to have a circle and a rectangle and when they collide the rectangle is erased,it’s just gone out of the program. So how do I do the erasing? I got the other part down.

Please tell us how you are creating the rectangles that you want to destroy. Do you use multiple calls to rect(), do you have a rectangle array, are they derived from a special class?

multiple calls to rect()

Are they numbered in any way. How do you know which one was hit?

yeah,I use vectors for the coords of the rectangles and I name them brick1,brick2 so on

Setting all the parameters to zero doesn’t work? You are not allocating memory for each brick so perhaps that would work?

so I do brick1.set(0,0) for example so it teleports in the corner and then I do w1,h1=0 so the width and height are also 0 and it disappears but for some reason it still counts as being in the program,the ball either bounces off of it if I don’t move it in the corner,or if I move it,it sometimes gets stuck on it and glitches out. Especially if I put multiple rectangles in the same corner

The only thing I can think of that might work is .remove(), but your bricks would have to be in a list. Other forum members might have a better suggestion.

I think I actually found the solution,I basically sent them to -500,-500 somewhere in the void out of the window

1 Like