I’m trying to make a simple hacky sack game for school and am wondering what the best way to do my graphics is. Basically what i want to have is a background image, with my character sprite on top of that with a hacky-sack sprite on top of that. Those two sprites will obviously have to be able to move and be interacted with. What should I be using to implement this? Sorry if this is a horrible question.
Also, as of right now, i’m trying to do it all in a Jpanel, but i cant draw one thing on top of the other without getting my background color to cover everything outiside the image i’m using. So, i’m not sure if i’m erasing my background image and drawing this new image over it or not.
You can use some kind of JComponent, possibly a JPanel, then override its paintComponent method to do the following:
- draw the background image
- draw the other stuff by using bitmasked or translucent images: use the createCompatibleImage(width,height,transparency) method of a GraphicsConfiguration object, where transparency is java.awt.Transparency.BITMASK or .TRANSLUCENT.
Then you can add a mouse/key listener to the JPanel, thus enabling the interaction part. The game can run by continually calling repaint() on the JPanel and update() on whichever class controls the game state (making the sprites move by incrementing positions, velocities, etc.).
You can use more advanced means (active rendering, etc.), but don’t try just yet. For the specifics you can consult the API pages which have links to how-to-use-Something tutorials.
I guess you’ll have to be more specific if you want more detailed help 