• Advertisement
Sign in to follow this  

Sprites

This topic is 2680 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

Hello,

I just started game programming and I am also glad to be here.
I wanted to know something while reading about sprites etc.
for example if 1 bmp image with a lot of frames inside I don't get how you could for example get 1 frame in a bitmap while its only 1 image,unless for example you get the rect coordinates of next frame itself could someone shed some light for me please.
thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
unless for example you get the rect coordinates of next frame itself

Why can't you get the rect coordinates?

If I have an image that's 100 pixels wide and 10 pixels tall, and my individual frames are 10 by 10 pixels, then I can just go:
numberOfFramesInImage = sizeOfImage / sizeOfFrame
If my images are 10 by 10 pixels, and I want to get frame number 3, I can go:
positionOfFrame = frameNumber * sizeOfFrame

//Psuedo-code:

imageWidth = ??
imageHeight = ??

frameWidth = ??
frameHeight = ??

-----------------------

maxNumberOfFramesHigh = imageWidth / frameWidth;
maxNumberOfFramesWide = imageHeight / frameHeight;

frameX = 5; //I want to get the 5th frame horizontally,
frameY = 3; //and the 3rd frame vertically.

//This is the pixel position of the start of the frame, from inside of the image.
positionX = frameX * frameWidth;
positionY = frameY * frameHeight;

GetFrameFromImage( positionX, positionY, frameWidth, frameHeight )




What API or library are you using (SDL, SFML, OpenGL, DirectX, etc...)? What programming language?


Welcome to GameDev.net, btw. [smile]

[Edited by - Servant of the Lord on October 21, 2010 2:21:10 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Servant of the Lord
Quote:
unless for example you get the rect coordinates of next frame itself

Why can't you get the rect coordinates?

If I have an image that's 100 pixels wide and 10 pixels tall, and my individual frames are 10 by 10 pixels, then I can just go:
numberOfFramesInImage = sizeOfImage / sizeOfFrame
If my images are 10 by 10 pixels, and I want to get frame number 3, I can go:
positionOfFrame = frameNumber * sizeOfFrame

//Psuedo-code:
*** Source Snippet Removed ***

What API or library are you using (SDL, SFML, OpenGL, DirectX, etc...)? What programming language?


Welcome to GameDev.net, btw. [smile]


thank you for your reply.

I see now I understand now you calculate the frame by getting its rectangle coordinates.

just got confused about dealing with Sprites because I have always dealed with a bitmap image that had only 1 frame while programming normal windows apps.

I am currently learning DirectX language C,so hopefully I will get into the realm of Game programming soon :D.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement