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
| 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 = sf3.Sprite.createVolatileImage(Toolkit.getDefaultToolkit().createImage(""), 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.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);
frame.getBufferStrategy().show(); // <- ici c buggé
//offG.dispose();
g2.dispose();
}}).start();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new AnimationDemo3();
}
} |
Partager