How to use sprite sheets?
#8
(09-09-2022, 01:23 PM)40wattstudio Wrote: Tada! Got it to work (in a standalone environment). The tricky part will be implementing it into the game.

Here's the code I used. It differs from what bplus had in that instead of trying to show specific images, I am simply cycling through a sequence of frames to show an animation.
It was a bit less painful than I thought it would be, although it certainly helps when all your images are the same width and height.
Some spritesheets optimize space by trimming them even further, which makes a mess of your width/height dimensions. To take it a step further, some spritesheets even simplify your sprites to polygons. Thankfully I don't need that degree of optimization, sounds like diminishing returns and a mathematical headache.
Code: (Select All)
CLS
SCREEN _NEWIMAGE(1000, 1000, 32)

DIM SHARED deathss AS LONG
DIM SHARED r AS INTEGER
DIM SHARED c AS INTEGER
deathss = _LOADIMAGE("SCRAPSHIP\x\gfx\death\deathSS.png")
_SOURCE deathss
_SOURCE 0
r = 0  'row
c = 0 ' column

DO WHILE c < 8
    DO WHILE r < 8
        DeathAnimation 0, 0, r, c
        r = r + 1
    LOOP
    IF r >= 8 THEN r = 0
    c = c + 1
LOOP

SUB DeathAnimation (x, y, r, c)
    _LIMIT 20
    rh = 200 * r + 1
    ch = 200 * c + 1
    CLS
    _PUTIMAGE (x, y), deathss, 0, (rh, ch)-(rh + 200, ch + 200)
END SUB

Sorry I'm late to the discussion but did you check out the tutorial that shows how to use sprite sheets in a few different ways? Here is a link:

https://qb64sourcecode.com/task18.html

My preferred method is to load the sprite images into an array.

Terry
Reply


Messages In This Thread
How to use sprite sheets? - by 40wattstudio - 09-09-2022, 12:39 AM
RE: How to use sprite sheets? - by James D Jarvis - 09-09-2022, 12:50 AM
RE: How to use sprite sheets? - by mnrvovrfc - 09-09-2022, 12:57 AM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 02:47 PM
RE: How to use sprite sheets? - by bplus - 09-09-2022, 01:52 AM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 02:00 AM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 01:23 PM
RE: How to use sprite sheets? - by TerryRitchie - 09-09-2022, 02:34 PM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 02:43 PM
RE: How to use sprite sheets? - by 40wattstudio - 09-12-2022, 10:31 AM
RE: How to use sprite sheets? - by TerryRitchie - 09-13-2022, 01:53 AM
RE: How to use sprite sheets? - by 40wattstudio - 09-09-2022, 01:57 AM
RE: How to use sprite sheets? - by Pete - 09-12-2022, 03:54 PM



Users browsing this thread: 5 Guest(s)