Working with Sprites.

BlitzMax Forums/BlitzMax Beginners Area/Working with Sprites.

allranger(Posted 2012) [#1]
I am trying to create a Sprite handler for my code. I am getting a little hung up on some of the concepts. I have read several tutorials but they do not seem to cover more advanced sprite animations.

Here is the code I came up with:

Type TAnimation
Field AnimName:String
Field Image:TImage
Field X:Int
Field Y:Int
Field Frames:Int[] = [9,19,29]
Field CurrFrame:Int
Field AnimTimer:Int = MilliSecs()
Field AnimSpeed:Int = 250

Function Create:TAnimation(Name:String,File:String,CellWidth:Int,CellHeight:Int,FirstCell:Int,TotalCells:Int,Frames:Int[])
Local Anim:TAnimation = New TAnimation
Anim.Image = LoadAnimImage(File,CellWidth,CellHeight,FirstCell,TotalCells)
AnimName=Name
X=100
Y=100
End Function

Method Update()
If MilliSecs() - AnimTimer > AnimSpeed Then AnimTimer = MilliSecs() ; CurrFrame:+1
If CurrFrame > Frames.Length - 1 Then CurrFrame = 0
End Method

Method Render()
'If KeyDown(Key_Down) And KeyDown(Key_S)
DrawImage Image,X,Y,Frames[CurrFrame]
'End If
End Method
End Type

Now for some questions.

I have been able to animate my character when dealing with 'simple' sprite sheets. All the animations for walking to the left on one sheet, for example. Now I am trying to work with a character sprite sheet that has all the actions that the player can do on one sheet. (Here is an example of the idea I want to work with here: http://media.photobucket.com/image/mario-3%20Fire/SpoonyBardOL/mario-3.gif)
The idea being that when the player gets new upgrades, a new gun, a shield, etc. I can have a variable that records the current character upgrade level, which in turn will have it use a different sprite sheet that has the actions all in the same spot but just has the gun or shield added to the sprite picture.
I am a little confused on how to cut up the sprite sheet so that each animation is connected in the end.
What I came up with is an array that holds the frames for each animation, and a string that holds the animation name. (e.g. "jumping").

But this seems bad because I am calling this function each time:

TAnimation.Create("Pull","C:\Program Files\BlitzMax\tmp\mario-3(Fire).png",80,80,0,100,[17,27])

So it seems like I am loading the whole sprite sheet each time just to get two frames out of it. That would be bad for memory. Is there a better way?

Can some one point me in the right direction?
Thanks.


Jesse(Posted 2012) [#2]
you can pass a pixmap instead of the file name to the LoadAnimImage function.


allranger(Posted 2012) [#3]
Okay, after reading the help file that sounds like what I am looking for.

So I would load the file as a pixmap and then just load the animations from the pixmap. Perfect. Thanks!

Does anyone have any ideas on handling the different frames for the animations. I am using an array, but should I be using a list or something else?