GLBasic forum

Main forum => GLBasic - en => Topic started by: StevetS on 2013-Mar-31

Title: GLBasic Extract Sprites from a Sprite Sheet
Post by: StevetS on 2013-Mar-31
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.

Title: Re: GLBasic Extract Sprites from a Sprite Sheet
Post by: Ian Price on 2013-Mar-31
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.
Title: Re: GLBasic Extract Sprites from a Sprite Sheet
Post by: StevetS on 2013-Mar-31
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! :)
Title: Re: GLBasic Extract Sprites from a Sprite Sheet
Post by: bigtunacan on 2013-Mar-31
StevetS, what application are you using to create your sprite sheets?
Title: Re: GLBasic Extract Sprites from a Sprite Sheet
Post by: Moru on 2013-Apr-01
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...
Title: Re: GLBasic Extract Sprites from a Sprite Sheet
Post by: StevetS on 2013-Apr-02
Thanks Moru,

I'll have a look at that.