How to use sprite sheets?
#13
(09-12-2022, 10:31 AM)40wattstudio Wrote:
(09-09-2022, 02:34 PM)TerryRitchie Wrote: My preferred method is to load the sprite images into an array.

Hi Terry,

So I tried loading graphics via sprite sheet in 2 different ways:

1) Just loading the sprite sheet and referencing the sprites I needed.

2) Loading the sprite sheet and adding the sprites into an array (your preferred method).

Option 2 is indeed nice if you want to have greater control over which frames get shown. Using this method, I was able to easily "rewind" an animation.

However, from a game design standpoint, it needs to be pointed out that option 2 comes at the cost of load time.

When I loaded just the sprite sheet (option 1), I could get all the graphics in the animation to show in about 1.15 seconds.
Option 2 increased the load time to 2.25 seconds.

Yep, there are trade-offs. Have you ever noticed when big name games start they usually have a few logos that fade in and out highlighting the companies involved in the project. What you don't see is during that time the assets (images, sounds, etc..) are getting loaded behind the scenes and processed. Many times during cut scenes in games the same is happening. With a little clever coding the load times can be made irrelevant.

I still prefer placing sprites into arrays because in the long run code becomes efficient. It's faster to reference and index number for an image than it is to calculate the locations on a sprite sheet and have _PUTIMAGE clip the image for you each time you need it. My original Sprite library uses referencing and although it works well it gets painfully slow when needing to access many images over and over again.

And then another issue arises when you need to rotate or zoom a sprite. You need to reference it, put it into at least a temporary image holder, rotate and/or zoom the sprite, then finally use it on the screen. I feel it's much better to pre-calculate all the zooming and rotating you'll need and put those images into an array. During that precalc period come up with a nifty logo sequence when your game starts to mask whats going on.
Reply


Messages In This Thread
How to use sprite sheets? - by 40wattstudio - 09-09-2022, 12:39 AM
RE: How to use sprite sheets? - by James D Jarvis - 09-09-2022, 12:50 AM
RE: How to use sprite sheets? - by mnrvovrfc - 09-09-2022, 12:57 AM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 02:47 PM
RE: How to use sprite sheets? - by bplus - 09-09-2022, 01:52 AM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 02:00 AM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 01:23 PM
RE: How to use sprite sheets? - by TerryRitchie - 09-09-2022, 02:34 PM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 02:43 PM
RE: How to use sprite sheets? - by 40wattstudio - 09-12-2022, 10:31 AM
RE: How to use sprite sheets? - by TerryRitchie - 09-13-2022, 01:53 AM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 01:57 AM
RE: How to use sprite sheets? - by Pete - 09-12-2022, 03:54 PM



Users browsing this thread: 5 Guest(s)