GLBasic Extract Sprites from a Sprite Sheet

Previous topic - Next topic

StevetS

Hi,

I'm after advice on how to import images from a sprite sheet into GLBasic.

I've been using the LOADANIM command to date which allows selection of width and height of each image but I'm wondering on the best way to do this when I want the 8 images in a sprite sheet to each have a different sprite number, rather than a different frame number of the same image.

I could split my images and load them individually but it would be simpler if I can combine them all in the same image (sprite sheet).

Many thanks,

Steve.

PLOT 50,50:DRAW 50,50,45454545

Ian Price

Well, you could load in the single spritesheet using LOADSPRITE and create an array that held the X,Y, Width & Heights of each of the sprites on the sheet. Then draw a magenta (RGB 255,0,128) background and draw your spritesheet onto it (this will ensure that transparency is maintained). You could then use GRABSPRITE Sprite#,X,Y,WIDTH,HEIGHT (in a loop) at the positions in the array and it will create new sprites out of the spritesheet. It's longwinded, but it works. Not sure it's worth all the effort though.

Be aware that GRABSPRITE may not work correctly on all devices and may be slow.
I came. I saw. I played.

StevetS

GRABSPRITE - that'll do it! Thanks.

Though if I'm looking for something to potentially be cross-platform I might just split the sprite sheet and load them individually.

Cheers! :)
PLOT 50,50:DRAW 50,50,45454545

bigtunacan

StevetS, what application are you using to create your sprite sheets?

Moru

Here is code for another way of doing it I think:
http://www.glbasic.com/forum/index.php?topic=6869.msg55619#msg55619

I would suggest to stay with one sprite sheet since that improves speed on some platforms. Ofcourse this means sprite collisions will be more work to set up...

StevetS

Thanks Moru,

I'll have a look at that.
PLOT 50,50:DRAW 50,50,45454545