Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Brin

2D Animation with SDL

This topic is 6192 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright, I have a bmp file that is 800 x 800,with 4 rows of cells, and 4 colums of cells. Each ''cell'' is about 200 x 200 Now, how do I offset on the image, and cause an animation? Code would be nice -Brin Perpetual

Share this post


Link to post
Share on other sites
Advertisement
That''s quite simple. Unfortunately, I don''t sit with SDL, I make my own stuff, so I''ll try to write it easy:

char *img;

// Load your image
loadImg("img.bmp", &img, &width, &height);

// Now width is 800 and height is 800

// Draw sprite 0x0 (X coordinate and Y coordinate!)
// NOTE: this function CANNOT be linear, must have offset
// calculation for all pixels!
drawImg(img, 0, 0, width, height);

// Draw sprite 1x0
drawImg(img, 200, 0, width, height);

// Therefore, to get the sprite XxY, we call this:
drawImg(buffer, X * w, Y * h, w, h);

Drawing sprite 2x3 will result in 400, 600, which is the
correct offset in the image.

A question:
Do you need an image that''s 800x800? Why don''t you make an image that''s 3200x200 instead? Sprites are easier to draw from such a structure and it''s easier to optimize it.

Share this post


Link to post
Share on other sites
Well 800x800 was just an example..
But i'm not sure I understand WHY you would multiply.

Because the top left corner of screen is 0, 0.
The bottom right is 1024, 768.

And my image is at 500, 500.

And how does multiplying the width by x and y give me the offset?

Just kinda strange for me to understand

To me it sounds like it would expand the image and then blit it with a new width not relocate it within the file.

Actually as I write it, it is beginning to make sense. But still an explanation if you could would help ;P


Edited by - Brin on August 8, 2001 9:26:30 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!