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


2D Animation with SDL

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
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