Images in Java (part 4)
Outline
Page 1
- Image formats: ImageIcon, Image, BufferedImage
- Converting from one to another
Page 2
- Loading images from disk
- Drawing onto Jpanel
- Writing images to disk
- Rescaling images
Page 3
- using a resouce folder to store images
- making a Jar file with images included
» Page 4 «
- Sprites
- Complete program for sprite animation
Complete code to demonstrate animation of sprite
In this program, we read in two images: one is an asteroid, the other is a spritesheet of explosions. Both images are below. You can right click on them and save them in order to run this yourself.
- read in images
- draw asteroid on screen
- user clicks on asteroid
- this starts a timer that runs through one of the explosions
- at the end of the explosion sequence, the timer stops and the asteroid is redrawn in a random location
- repeat
Java Code
Explode.java
Sprites and Images
"green_asteroid.png"
There are 8 rows. Each has 14 sprites in it. Each sprite is 64x64 pixels.
This is not the best spritesheet as you can see that some are truncated.
"explosions.png"