Results 1 to 4 of 4
Thread: Playing an Animated GIF
- 04-03-2009, 12:03 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 2
- Rep Power
- 0
Playing an Animated GIF
I am trying to play an animated gif in my little maze game. It's the player's gif, which should play an animation to make it look like the player has spawned into the game (thus it should only play once).
So i have stored it in a BufferedImage, drawn it and sent the panel as the imageObserver, but it only puts the first frame of the gif and doesnt go on to the next..
In the code, that is:
And in the paintComponent (along with many other things being painted):Java Code:String a = System.getProperty("user.dir"); BufferedImage plr; File dir = new File(a + "\\player2_mfmaze.gif"); plr = ImageIO.read(dir);
Any idea? Or maybe i should just use an lib to do the job? (Suggest one if thats the case)Java Code:g.drawImage(plr, (int) (playerX * blocksize+1), (int) (playerY * blocksize+1), (int) (blocksize-1), (int) (blocksize-1), this);// this == JPanel
Thanks in anticipation!!
- 04-04-2009, 05:09 AM #2
Try one of the following:
1) Load the image using Toolkit instead of ImageIO.
OR
2) Construct an ImageIcon and call the paintIcon method from your paintComponent override.
If neither suggestion solves the problem, post back and I'll take another look.
db
- 04-04-2009, 12:49 PM #3
Member
- Join Date
- Apr 2009
- Posts
- 2
- Rep Power
- 0
Using Image instead of Buffered Image and Toolkit instead of ImageIO worked.
I guess the buffered image or imageIO is for only one static frame of a gif.
Thank you for your help! :)
- 04-24-2009, 10:47 AM #4
Member
- Join Date
- Apr 2009
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
Animation with Animated GIF
By JavaBean in forum Java 2DReplies: 3Last Post: 06-04-2011, 04:26 PM -
Extracting jpg from animated gifs
By Maz in forum Java 2DReplies: 3Last Post: 05-05-2011, 12:29 PM -
Animated JPanels + Moving Pages
By PetalumaBoy in forum New To JavaReplies: 0Last Post: 02-16-2009, 11:09 AM -
playing audio in J-App??
By ashton in forum New To JavaReplies: 3Last Post: 01-30-2009, 08:50 AM -
Re-playing sound
By JSK in forum CLDC and MIDPReplies: 0Last Post: 02-06-2008, 11:34 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks