1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
   | /*
 * Main.java
 *
 * Created on 15 novembre 2006, 04:32
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
 
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.image.VolatileImage;
import java.awt.GraphicsConfiguration;
import java.net.URISyntaxException;
import javax.swing.JFrame;
import quicktime.std.anim.Sprite;
import quicktime.std.clocks.TimeRecord;
import sf3.*;
 
/**
 *
 * @author website
 */
public class AnimationDemo3{
    JFrame frame;
    AffineTransform tx;
    Animation anim;
    SpritesChar character = SpritesChar.characters.get("Ryu");
    VolatileImage offscreen;
    static int ticktime = 10;
 
    private MediaTracker mt;
    private Dimension size = new Dimension(400,340);
 
    /** Creates a new instance of Main */
    public AnimationDemo3() {
        frame = new JFrame("Animation Demo - sf3jswing project @sf.net");
        //frame.setLocationRelativeTo(null);
        frame.setIgnoreRepaint(true);
        frame.setPreferredSize(size);
        frame.setSize(size);
        frame.setVisible(true);
        frame.pack();
        tx = AffineTransform.getScaleInstance(1.0,1.0);
        offscreen = createVolatile(size);
        System.out.println(getClass().getResource("Main.class"));
        try {
            anim = new Animation("ryu", character.frames[0][0], character.frames[0][1], character.prefix, character.suffix + ".png", "png", new Dimension(character.spriteWidth,character.spriteWidth), mt = new MediaTracker(frame));
            anim.setResourceEnabled(true);
            anim.setSwapDiskCacheEnabled(true);
            anim.waitForAllActivity(anim.cacheResources());
        } catch(URISyntaxException e) { e.printStackTrace(); } finally {
            frame.createBufferStrategy(2);
            frame.getBufferStrategy().show();
            new javax.swing.Timer(ticktime, new ActionListener() { public void actionPerformed(ActionEvent e) {
                Graphics2D g2 = (Graphics2D)frame.getBufferStrategy().getDrawGraphics();
                if(anim.status() != Animation.PLAYING) { anim.rewind(); anim.play(); }
                Graphics2D offG = (offscreen.contentsLost())?(offscreen = createVolatile(size)).createGraphics():offscreen.createGraphics();
                offG.drawRect(0,0,size.width, size.height);
                offG.drawString("ANIMATIONS GRAPHICAL DISPLAY", 50, 50);
                anim.draw(offG);
                g2.drawImage(offscreen, tx, frame);
                //anim.draw(g2); g2.drawString("ANIMATIONS GRAPHICAL DISPLAY", 50, 50); // no offscreen
                frame.getBufferStrategy().show();
                //offG.dispose();
                //g2.dispose();
            }}).start();
        }
    }
 
    public VolatileImage createVolatile(Dimension size) {
        return sf3.Sprite.createVolatileImage((Image)frame.getGraphicsConfiguration().createCompatibleImage(size.width, size.height), size);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        AnimationDemo3 main = new AnimationDemo3();
    }
 
} | 
Partager