What I want to do is take my rpg man sprite and understand how I can access each of his eight animations with methods. I've looked at code that does something like this but I'm not quite getting it. Right now, I got my guy to do two seperate animations from two separate bmps and he's facing forward in every direction he goes.So it looks like he's walking forward all the time. I guess what I am asking is how do I go about accessing all eight of his animations from a single bmp and assign them to the direction I want that animation to go to?

Well, your bmp, is it done the standard way of having in effect the 8 pictures side by side in say a 2 row, 4 column format? If so you have to copy the relevant "frame" out of that picture and place it on the screen

Yeah I saved it in 24-bit bmp format. All a straight line of 8 individual animations. So what do I do? I know I'm supposed to make a private int for the frame variable.

so should I have something like this.

private int frame = 0;

or something like this?

Rectangle[] rectFrames = new Rectangle[8];

also I know I should have my bmp's width and height. width = 31 height = 43
But where I get confused is when I try to assign animations to the direction I want my character to move. I want two animations for each direction I want my little man to move in. So basically, I have two questions. One how do I access my frame animate from one bmp seperately and two where do I put these methods so i can get the desired effect?

As I said you need to copy out the relevant "frame" from within your big picture. Doing it into an array is often easiest to code with later.

so if your picture was in the format

1 2 3 4
5 6 7 8

(numbers representing your man in a frame)
you use some maths, to extract each of the bitmaps (either by calculating the size of the picture given the original size of the image and the number of "frames" wide and tall, or by specifying them, and then copy that section into a new picture in your array of mini pictures constituting a frame.

Then to play the animation you would use a timer (or similar) to change the image to the next in rotation every interval you pick.

Ok that explains quite a bit for me. Thank you Liz. I will get to working on the code right.

I believe this bit of code here is the heart of what I want to do.

for(int i=0; i< nFrames; i++)
        {
            Point pt = new Point(Hero_width * i, 0);
            frames[i] = new Rectangle(pt, new Size(Hero_width, Hero_height));
        }

Am I on the right track?

And while I'm at it here is the timer function I've written:

private void TimerSprite_Tick(object sender, System.EventArgs e)
    {
        if(currentframe >= nFrames - 1)
        {
            currentframe = 0;
        }
        else
        {
            currentframe++;
        }
    }

I've gotten it so that I can get bmp file to run through all of its animations now I gotta figure out how to assign those animations to each key.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

There are ways you could improve it, but its on the right track.

Something you might want to investigate are the "mod" or % maths functionality

This article has been dead for over six months. Start a new discussion instead.