Hey guys,
So I've been wanting to figure out how to use sprites in Java. I know how the concept works and all that, since I've used them in html/css for a while now.
But I'm not sure how to implement it in Java? Also, how can i make them so that the sprites are in, say 8 colors, and those colors can be changed on the fly by the game?
As far as changing the pixels of a sprite in java 'on the fly', I know no such way.
But for sprites, I could help you out =D.
You're going to want to create a ImageIcon first for the sprite, than list the path for it, than draw it using java Graphics.
1
| public ImageIcon tree = new ImageIcon("src/server/cache/tree.png"); |
Next you're going to want to create a method to actually draw the tree/picture you're choosing.
1 2 3
| public void paint(Graphics g) { g.drawImage(tree, 0, 0, null); } |
Hope i'm not to late, believe everything above should work, but other members here frown upon the way i do things so wait for others opinions if mine doesn't cut it for drawing sprites.