J'ai trouvé une classe pour faire un fichier gif contenant plusieurs animations d'image devant une image d'arrière-plan. Ceci est ma classe:Animation de sprites et de C#
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace AnimSprites {
public class AnimSprite {
private int frame, interval, width, height;
private string imgFile;
private Image img;
private Timer frameTimer;
public AnimSprite(string f_imgFile, int f_width) {
frame = 0;
width = f_width;
imgFile = f_imgFile;
img = new Bitmap(imgFile);
height = img.Height;
}
public void Start(int f_interval) {
interval = f_interval;
frameTimer = new Timer();
frameTimer.Interval = interval;
frameTimer.Tick += new EventHandler(advanceFrame);
frameTimer.Start();
}
public void Start() {
Start(100);
}
public void Stop() {
frameTimer.Stop();
frameTimer.Dispose();
}
public Bitmap Paint(Graphics e) {
Bitmap temp;
Graphics tempGraphics;
temp = new Bitmap(width, height, e);
tempGraphics = Graphics.FromImage(temp);
tempGraphics.DrawImageUnscaled(img, 0-(width*frame), 0);
tempGraphics.Dispose();
return(temp);
}
private void advanceFrame(Object sender, EventArgs e) {
frame++;
if (frame >= img.Width/width)
frame = 0;
}
}
}
Comment puis-je utiliser cette classe pour faire mon fichier GIF (de running_dog.gif) courir sur background.jpg de gauche à droite?
C'est le fichier dog.gif: dog.gif
Il doit aller de gauche à droite et chaque étape est une image différente dans le fichier gif. Donc, fondamentalement, il doit aller de feft à droite et de haut en bas (dans le gif) en même temps. –
Merci pour votre aide! Maintenant, j'ai une division par zéro exception cependant. –
Juste pour être sûr, c'est la façon de l'appeler non? AnimSprites.AnimSprite P = nouveau AnimSprites.AnimSprite ("running_dog.gif", 100); P.Start(); –