Page 1 of 1

Sprite sheets

Posted: Sat Jun 08, 2019 6:06 pm
by richmond62
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 7518 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 . . .

Re: Sprite sheets

Posted: Sat Jun 08, 2019 6:25 pm
by richmond62
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.

Re: Sprite sheets

Posted: Sat Jun 08, 2019 6:29 pm
by richmond62
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.

Re: Sprite sheets

Posted: Sun Jun 09, 2019 10:17 am
by richmond62
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.

Re: Sprite sheets

Posted: Sun Jun 09, 2019 10:39 am
by richmond62
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?

Re: Sprite sheets

Posted: Sun Jun 09, 2019 10:46 am
by [-hh]
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) .

Re: Sprite sheets

Posted: Sun Jun 09, 2019 11:48 am
by richmond62
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 7422 times

Re: Sprite sheets

Posted: Sun Jun 09, 2019 1:15 pm
by richmond62
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.

Re: Sprite sheets

Posted: Sun Jun 09, 2019 1:51 pm
by richmond62

Re: Sprite sheets

Posted: Mon Jun 10, 2019 2:58 pm
by bwmilby
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.

Re: Sprite sheets

Posted: Mon Jun 10, 2019 9:32 pm
by richmond62
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.

Re: Sprite sheets

Posted: Tue Jun 11, 2019 4:38 am
by FourthWorld
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.