Skip to content
Advertisement

How to initialize and draw a Rectangle variable in a paintComponent method? [closed]

I’ve been trying to add collision to my game, it seemed like a piece of cake, I already know how to draw a rectangle. But I need that rectangle to be represented by something, a variable. But it seems like there’s no method like g.drawRect(myRectangleVariable). I need to do some if statements checking for intersection but if I don’t have a rectangle variable then what do I compare? If you guys need any of my code just tell me.

Advertisement

Answer

Why not just do

g.drawRect(myRectangleVariable.x, 
           myRectangleVariable.y, 
           myRectangleVariable.width, 
           myRectangleVariable.height);
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement