Grabbing Sprites from an Image sheet

BlitzMax Forums/BlitzMax Beginners Area/Grabbing Sprites from an Image sheet

Tummy(Posted 2008) [#1]
Hi,

I want to place all sprites for my game on one image sheet, then pull sprites off the sheet to use in game.

Please point me to a forum post, tutorial or code example?

Thanks!


GfK(Posted 2008) [#2]
Use LoadAnimImage().


Tummy(Posted 2008) [#3]
Hi GfK,

Thanks.

I checked the LoadAnimImage command and the syntax is ("path$",width,height,start,count). I see how this would work for one anim strip, say a 6 frame strip of 32x32 squares (32,32,0,5) 192x32.

But say I have 3 of the above strips, each 192x32 on one image sheet 192x96, and I want to grab all 3 as seperate sprite strips? Is there a way to offset the starting x,y coordinates?

Scot


MikeT(Posted 2008) [#4]
if i remember correctly you just use the start part, e.g. if your next sprite strip starts at position 6 and lasts for 5 frames you would call (path$,32,32,6,5) that is if the image3s are 32x32 in size.

Hope that helps

Mike


GfK(Posted 2008) [#5]
^^what he said.

Just be aware though, that LoadAnimImage(path$,32,32,5,5) will still result in an animated image with five frames, numbered 0-4, not 5-9 as the syntax might imply.


Tummy(Posted 2008) [#6]
Hi MikeT,

I'm sorry, I should have explained it better. The image is 192x96 and it contains 3 animated sprite strips as rows, not side by side. Each sprite strip is 6 frames, each frame is 32x32:
- first sprite strip is located at 0,0 and is 192 wide by 32 tall
- second sprite strip is located at 0,32 and is 192 wide by 32 tall
- third sprite strip is located at 0,64 and is 192 wide by 32 tall.

I want to grab each of the three seperately. Granted maybe I just use 1 png per animated sprite, but Ideally I'd like to use one png for all the sprites in the game.

Thanks,

Scot


GfK(Posted 2008) [#7]
Think you might have misread MikeT's reply.

myImage1:TImage = LoadAnimImage(path$,32,32,0,5)
myImage2:TImage = LoadAnimImage(path$,32,32,5,5)
myImage3:TImage = LoadAnimImage(path$,32,32,10,5)

That will load your 3 separate animations, from the same file, into 3 separate TImages.

LoadAnimImage loads images from left to right. When it reaches the right hand side of the image, it goes down to the next row, and so on. The images in a so-called animstrip don't need to be horizontally arranged. For example, you could load a five-frame 32x32 animation from a 32 wide x 192 high image, or from a 192x32 image, or from a 64x96 image (although there'd be a blank frame in the lower right corner of the image file, in that case, since an image that size could contain six frames).


Tummy(Posted 2008) [#8]
Hi GfK,

Yep, I misread :) and thanks to both of you!