| | |
Can someone explain the concept of bitmap animations to me
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
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?
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
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?
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?
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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.
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.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
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.
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.
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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
Something you might want to investigate are the "mod" or % maths functionality
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
![]() |
Other Threads in the C# Forum
- Previous Thread: file path help
- Next Thread: Trouble logging into sql server
| Thread Tools | Search this Thread |
.net access algorithm alignment app array barchart bitmap box broadcast c# c#gridviewcolumn cast check checkbox client combobox communication control conversion csharp custom database datagrid datagridview dataset datatable datetime degrees development draganddrop drawing elevated encryption enum excel file focus form format forms function gdi+ hospitalmanagementsystem httpwebrequest image index input install java label list listbox localization login mandelbrot math messagebox mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser whileloop windows winforms wpf xml






