Sprite sheets

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3334
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Sprite sheets

Post by richmond62 » Sat Jun 08, 2019 6:06 pm

Ooooer . . . I am getting fed up of having to chop animated GIF images and sprite sheets
up into individual frames . . .
-
boy_sprite_sheet.png
-
Now . . . apart from the fact that an awful lots of ways to make games leverage sprite sheets
(which cuts down storage and speed overheads considerably) . . . it would be groovy if . . .
-
shaggy_groovy.jpg
shaggy_groovy.jpg (24.67 KiB) Viewed 558 times
-
one could use sprite sheets in LiveCode . . .

And here is where the Richmond Fantasy Thingy gets into high gear
and starts cooking up pseudo-code faster than you can say Sesquidepeleanism . . .

on mouseUp
set the backGroundPattern of grc "gFRAME" to the rect 0,175,0,286 of img "boy.png"
end mouseUp

Of course this isnae gonnae wark because when one
sets a backGroundPattern of a graphic object one has to reference the
image's ID rather than the image by name . . .

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3334
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Sprite sheets

Post by richmond62 » Sat Jun 08, 2019 6:25 pm

This example uses individual images for each animation frame:

http://newsletters.livecode.com/may/iss ... tter4.html

and does the whole thing is a hugely over-complicated fashion anyway.
Last edited by richmond62 on Mon Jun 24, 2019 10:05 pm, edited 2 times in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3334
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Sprite sheets

Post by richmond62 » Sat Jun 08, 2019 6:29 pm

https://codeshack.io/images-sprite-sheet-generator/

"You can use your favorite coding language to select the coordinates of each image
and display them accordingly" . . .

http://www.html5gamedevs.com/topic/2690 ... -with-gui/

Well, for some daft reason my favourite coding language is LiveCode, but I cannot
for the life of me work out how to select the coordinates of part of an image and display
that is some sort of a frame (button, field, graphic object, image) somewhere else on a stack.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3334
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Sprite sheets

Post by richmond62 » Sun Jun 09, 2019 10:17 am

This is where I am getting in the sh*t:

Code: Select all

   import snapshot from rect (the rect 0,175,0,286) of img "boy.png"
as I seem unable to take a snapshot of part of an image.

Of course, in the end this is also useless because I should
be able to display part of a sprite sheet inside some sort of container without
having to make an intermediate image.
Last edited by richmond62 on Mon Jun 24, 2019 10:05 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3334
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Sprite sheets

Post by richmond62 » Sun Jun 09, 2019 10:39 am

Cripes:

https://pdfs.semanticscholar.org/8888/b ... 24ceb4.pdf

"Sprite sheets on which all sprites have identical
sizes are easy to be loaded by a game engine. In that
case, one simply needs to specify the x- and y-offset to
get a particular sprite in the sheet and the
corresponding size for that sprite sheet images."

So why does it seem difficult to specify the offset?

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2027
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Sprite sheets

Post by [-hh] » Sun Jun 09, 2019 10:46 am

I should be able to display part of a sprite sheet inside some sort of container without having to make an intermediate image.
You could group the sprite sheet, set the group's clipsToRect to true.
Then set the rect of the group to display part of the sheet (or set the hscroll/vscroll of the group if the rect's width/height is constant) .
shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3334
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Sprite sheets

Post by richmond62 » Sun Jun 09, 2019 11:48 am

Thank you very much indeed.
That does work (although it involves a lot of fiddling around with numbers).
-
Sprite sheet test.png
-
Although, given the fiddling around that it involves
I wonder if it might not be better to "just" use individual files for frames.

The only advantage I can see about using a sprite sheet
is that the overhead in terms of file size should be considerably smaller.
-
Overhead.png
Overhead.png (31.98 KiB) Viewed 462 times
Attachments
Sprite Sheet test.livecode.zip
Here's the stack
(235.41 KiB) Downloaded 9 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3334
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Sprite sheets

Post by richmond62 » Sun Jun 09, 2019 1:15 pm

The "other" snag, and it is quite a significant snag, is this:

1. I made up that "Sprite Sheet" as a set of frames on
a transparent background (.png image).

2. "Normal" sprite sheets are not like that at all, but
generally have a checkered or solid colour background
that LiveCode is not going to ignore:
-
7814-450.jpg
-
therefore any sprite sheets for use with LiveCode have
to be specially created; which is just as much a fiddle as
setting up individual images for each frame.


bwmilby
Posts: 263
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Sprite sheets

Post by bwmilby » Mon Jun 10, 2019 2:58 pm

I recently saw a demo of using a sprite sheet with a group doing the clipping and it worked well. I believe that the performance of that method is much better than you can get showing different images.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3334
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Sprite sheets

Post by richmond62 » Mon Jun 10, 2019 9:32 pm

bwmilby

I am sure you are right.

My problem is how one can extract the sprites
surrounded by a transparent background when most
sprite sheets come with a one-colour background or
something checkered.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6671
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Sprite sheets

Post by FourthWorld » Tue Jun 11, 2019 4:38 am

Checkered usually indicates transparency. Or is it actually checkered when imported into LC? If so, send a bug report to the provider of the image, as such a background would make the image useless.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”