[solved]Rectangle

I already solved on how the game start with a SPACE KEY pressed and other issues I wanted to be.

And now I want a Rectangle to be dissolved after it collided with the ball.

And I tried to use the clearRec() but It didn`t work.

Am I using the right method?

if this is in Java2D I would just have a conditional statment:


if(hit==false){
graphics.drawRect(x,y,sizeX,sizeY);
}

And whenever the ball hits the rectangle just set hit to true.

Hope this helps at all.

If you want it to dissolve (I assume you mean fade) then you will have to draw the rectangle with lower and lower alpha once it collides with the ball.

Thank you for the quick reply.

then in that case I will change fillRect() to drawRect()?

I will give it a try.

@Sir Longarmx
It will not fade, I want to erase/remove the rectangle when the ball hits the rectangle.

I tried the drawRect() but the rectangle is hollow

so I use the code:

if (hit == false)
g.fillRect(x,y,w,h)

and it works.

Thanks Sir kingroka123

Instead of doing if(hit == true) you could just do if(hit) and if(!hit). Not a huge deal just good practice.

thanks for the info. sir :slight_smile: