• Advertisement
Sign in to follow this  

Loading and Working with Sprites

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

Can someone please point me in the direction of some tutorials on how to work with Sprites and load sprites that may be in the form of a Sprite Sheet that holds multiple sprites in one file? Do people take that sheet and cut it up in a graphics program or somehow use code to do load sections of the sprite sheet?

Share this post


Link to post
Share on other sites
Advertisement
not sure if this was what you were looking for, but you'll need, apart from your bitmap class, a sprite class.

Share this post


Link to post
Share on other sites
Ok, So the "sprite sheet" with all the sprites drawn on one file is loaded with a bitmap object and then somehow converted to a sprite object?

I can load an image using DirectX, but it's the files that have multiple images such as this one that I have trouble with.

http://www.nes-snes-sprites.com/TetrisGB.html


What I'm really looking for is some kind of tutorial, article, or book where I can read up on this and get a firm grasp on loading images for use in my games. I would prefer something online due to a cost issue.

Share this post


Link to post
Share on other sites
Quote:
Original post by murdock
Ok, So the "sprite sheet" with all the sprites drawn on one file is loaded with a bitmap object and then somehow converted to a sprite object?

Your view on thess bitmap and sprite objects looks a bit hazardous. You seem to be viewing each as a separate entity that is used uniquely and through very specific means. When in fact, a "sprite object" is likely to incorporate a bitmap object member variable, and a "bitmap object" in turn is just a collection of colored pixels, usually represented in sets of three floats or integers. Objects, typically, are extensions of more primitive objects which combine to form more complex objects. Looking at objects as completely unrelated is a good way to get yourself confused in the programming world.

That said, the general idea behind sprites is to load in a single image which is a combination of multiple images that form the animation of the sprite. Here's an example:


(click here if this image does not show)

The image shows a walking animation for all the different directions the character would move in the game. It would then be the coder's responsibility to cut up the image with some image-manipulation code or library and then process it from there. I don't have a tutorial on hand at the moment for doing that; there's no single way of doing this, since it's just basic image loading and cutting.

Assuming you have the image cut up into the pieces you need--in the above image, you'd want to cut each row into four even pieces, and store that somewhere--you then need to animate the sprite. Animating the image is done by quickly flipping between the multiple cuts of the image. In the first row, for example, if you wanted to animate the guy walking forward, you would rapidly loop through the four walking images, much like something would be animated in a flip-book. You have to be careful to add a time delay to each image, though, as looping too quickly through the images will animate too fast for the human eye to follow, plus it will just make the guy look like a super-hyper fast walker. This will need to be tweaked as well according to the speed of your game engine in order to achieve the right effect.

That's your basic process. From there, if you wanted to animate the guy walking left, you would just use the second row down. This change, of course, is detected through user input; when the user presses left on the keyboard, use the left-walking animation, when pressing right, use the right-walking animation, and so on. Sorry I don't have a tutorial, but at least this basic explanation should give you an idea, and perhaps a means of getting started.

That sprite in my post, btw, was pulled from this site. Has a ton of free sprites, in case you were looking for more.

[Edited by - Omega147 on June 15, 2007 3:47:19 PM]

Share this post


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

  • Advertisement