Hey There,
I’m making a Cellphone shooter style game, you know like you are the spaceship and you need to kill the enemy ships while dodging their bullets and such, its 2D… anyways… I’m trying to make a shooting mechanism, such that I could draw the bullet as it moves towards its target. Here is the thing, that wouldn’t be hard, but if another bullet is fired and such. I’m not sure how to handle that, I tried creating a new thread, for every bullet, to just iterate through a for loop, that would draw the bullet, sleep for 20ms, adjust the y coordinate and then reiterate. The issue is actually drawing though. Thus i get to my question, How do i draw outside of the paintComponent method? like can I pass the Graphics through the constructor into another class. Because if i make a thread in the paintComponent method and thus a public void run method inside of it it wants the Graphics to be final, but I couldn’t draw outside of the method, posing a slight problem as I couldn’t call another class or method to do the drawing by passing it the Graphics.
Is there something i’m missing or doing wrong?