You probably already know about sprite sheet and strips and how it can reduce the file size of your game. I recently started a new method on how I'm going to develop my game. It involves using sprite sheets for static sprites and sprite strips for animated sprites. This may sound odd but here's why...
Sprite sheets are great for loading a whole sheet of static images and clipping them before your repeat section. Not only does this save major space for your exe/app but all your static sprites are pre-clipped and ready to be displayed when you need them. Now you may wonder why I'm not suggesting sprite sheets for animation. Well, there's nothing wrong with doing so but read the next paragraph.
Sprite strips are great for animation. Animations are usually a few frames and you don't have to worry about going beyond the texture width that a graphics card can handle. Unlike putting a bunch of static images into a strip and easily going beyond 4096 in width. Which some gpu's can not handle. Also, sprite strips are smaller in file size then sprite sheets. Testing was done by using the same images for both. At least on OS X and I'm sure the same holds for Windows but don't hold me to it. The animation routine/procedure is smaller and quicker without having to calculate Y coordinates.
So I created a new procedure for animated sprite strips. This procedure does not calculate anything it doesn't need to and only clips static frames once. You can easily change the values of the procedure/new function within your loop. Such as going from an animation, such as running, to a still frame. There's also a return so you can easily find out what frame the current animation or still is on. This return is great if you want different events to happen depending on the frame that the event happens on. You can alter the fps of an animation too. If you want a still frame, just make "asStartFrame" and "asEndFrame" the same value and 0 for "asFpsDelay".
Anyway, here's the new code.

Code: Select all
Structure AnimatedSprites
asNextFrame.u
asClipOnce.u
asNextStill.u
asFps.u
asData.u
EndStructure
Procedure AnimateSprite(asSprite, asClipSquare, asStartFrame, asEndFrame, asFpsDelay) ;<--- For a still frame, use 0 for "asFpsDelay".
Static Dim asSprites.AnimatedSprites(100) ;<--- Set to the maximum #Sprite number you plan to use with this procedure.
If asSprites(asSprite)\asData <> 1 ;<--- Only need this data to start off with.
asSprites(asSprite)\asNextFrame = 0
asSprites(asSprite)\asClipOnce = 0
asSprites(asSprite)\asNextStill = asStartFrame
asSprites(asSprite)\asFps = 1
asSprites(asSprite)\asData = 1
EndIf
If asStartFrame + asSprites(asSprite)\asNextFrame > asEndFrame ;<--- Already clipped the last frame and need to start from the begining.
asSprites(asSprite)\asNextFrame = 0
EndIf
If asSprites(asSprite)\asNextStill <> asStartFrame Or asSprites(asSprite)\asNextStill <> asEndFrame;<--- If you go from one still frame to the next still frame or animation, we reset "asClipOnce".
asSprites(asSprite)\asClipOnce = 0
asSprites(asSprite)\asNextStill = asStartFrame ;<--- If we go to an animation, we don't want this "If" statement to keep calculating "asClipOnce = 0".
EndIf
If asStartFrame = asEndFrame And asSprites(asSprite)\asClipOnce = 0 ;<--- No need to keep clipping a still frame.
ClipSprite(asSprite, ((asStartFrame + asSprites(asSprite)\asNextFrame) * asClipSquare) - asClipSquare, 0, asClipSquare, asClipSquare)
asSprites(asSprite)\asClipOnce = 1
asSprites(asSprite)\asNextStill = asStartFrame
ElseIf asStartFrame < asEndFrame ;<--- Clipping for animation.
ClipSprite(asSprite, ((asStartFrame + asSprites(asSprite)\asNextFrame) * asClipSquare) - asClipSquare, 0, asClipSquare, asClipSquare)
EndIf
If asSprites(asSprite)\asFps = asFpsDelay ;<--- Checking for "frames per second" before going to the next frame.
asSprites(asSprite)\asNextFrame + 1
asSprites(asSprite)\asFps = 1
ElseIf asFpsDelay <> 0 ;<--- Not equal to a still frame or full blast 60fps animation or higher.
asSprites(asSprite)\asFps + 1
EndIf
ProcedureReturn asStartFrame + asSprites(asSprite)\asNextFrame ;<--- If you want an event to react different depending on the current frame number.
EndProcedure