Results 1 to 4 of 4
  1. #1
    c0m4ndo45 is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default 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:

    Java Code:
    String a = System.getProperty("user.dir");
    BufferedImage plr;
    File dir = new File(a + "\\player2_mfmaze.gif");        
    plr = ImageIO.read(dir);
    And in the paintComponent (along with many other things being painted):

    Java Code:
    g.drawImage(plr, (int) (playerX * blocksize+1),
                                    (int) (playerY * blocksize+1),
                                    (int) (blocksize-1),
                                    (int) (blocksize-1), this);// this == JPanel
    Any idea? Or maybe i should just use an lib to do the job? (Suggest one if thats the case)

    Thanks in anticipation!!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    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

  3. #3
    c0m4ndo45 is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default

    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! :)

  4. #4
    rexicon is offline Member
    Join Date
    Apr 2009
    Posts
    10
    Rep Power
    0

Similar Threads

  1. Animation with Animated GIF
    By JavaBean in forum Java 2D
    Replies: 3
    Last Post: 06-04-2011, 04:26 PM
  2. Extracting jpg from animated gifs
    By Maz in forum Java 2D
    Replies: 3
    Last Post: 05-05-2011, 12:29 PM
  3. Animated JPanels + Moving Pages
    By PetalumaBoy in forum New To Java
    Replies: 0
    Last Post: 02-16-2009, 11:09 AM
  4. playing audio in J-App??
    By ashton in forum New To Java
    Replies: 3
    Last Post: 01-30-2009, 08:50 AM
  5. Re-playing sound
    By JSK in forum CLDC and MIDP
    Replies: 0
    Last Post: 02-06-2008, 11:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •