943,731 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1208
  • C# RSS
Mar 4th, 2009
0

Can someone explain the concept of bitmap animations to me

Expand Post »
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?
Reputation Points: 10
Solved Threads: 1
Light Poster
Pikachumanson is offline Offline
45 posts
since May 2008
Mar 5th, 2009
0

Re: Can someone explain the concept of bitmap animations to me

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
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Mar 5th, 2009
0

Re: Can someone explain the concept of bitmap animations to me

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?
Reputation Points: 10
Solved Threads: 1
Light Poster
Pikachumanson is offline Offline
45 posts
since May 2008
Mar 5th, 2009
0

Re: Can someone explain the concept of bitmap animations to me

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.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Mar 5th, 2009
0

Re: Can someone explain the concept of bitmap animations to me

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.
Reputation Points: 10
Solved Threads: 1
Light Poster
Pikachumanson is offline Offline
45 posts
since May 2008
Mar 5th, 2009
0

Re: Can someone explain the concept of bitmap animations to me

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
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: file path help
Next Thread in C# Forum Timeline: Trouble logging into sql server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC