I want to create a simple game, similar to what can be created with RPG Maker. What I am primarily looking for at the moment is a tutorial which can guide me on how to accomplis
I threw together than example of what I think it is that you were after. This example can be applied to buttons or picture boxes. I chose this way of out of simplicity.
Each instance of an animation holds a timer, and a list of images. Updating the image of the target control whenever the timer fires its event.
I have uploaded my project file here. http://mcspazzy.com/code/ParTest.zip
Hopefully it is enough to help. Just ask if you need more explanation.
The class
public class Animation
{
readonly Timer _animtimer = new Timer();
public List Frames;
public int FrameIndex;
private Button _target;
private PictureBox _ptarget;
public void Target(PictureBox target)
{
_ptarget = target;
}
public void Target(Button target)
{
_target = target;
}
public int FrameSpeed
{
get { return _animtimer.Interval; }
set { _animtimer.Interval = value; }
}
public Animation()
{
Frames = new List();
_animtimer.Interval = 100;
_animtimer.Tick += Update;
}
public void Play()
{
_animtimer.Start();
}
public void AddFrame(string file)
{
Frames.Add(Image.FromFile(file));
}
public void Stop()
{
_animtimer.Stop();
}
private void Update(object sender, EventArgs eventArgs)
{
FrameIndex++;
if (FrameIndex == Frames.Count)
{
FrameIndex = 0;
}
_target.Image = Frames[FrameIndex];
_ptarget.Image = Frames[FrameIndex];
}
public static implicit operator Image(Animation a)
{
return a.Frames[a.FrameIndex];
}
}
This was in my Form load. Can really go anywhere that stuff is initialized.
private void Form1Load(object sender, EventArgs e)
{
_testAnim.AddFrame(@"F:\Im\Black.png");
_testAnim.AddFrame(@"F:\Im\Blue.png");
_testAnim.AddFrame(@"F:\Im\Green.png");
_testAnim.AddFrame(@"F:\Im\Orange.png");
_testAnim.AddFrame(@"F:\Im\Red.png");
_testAnim.Target(ButtonTest);
_testAnim.Target(PicBox);
_testAnim.Play();
}