Log In  

Hi All,

I wrote a small function to scale 8x8 sprites using a sprite number instead of using sspr() itself and having to pick out the x and y position each time.

I'm using it for the Toy Box Jam 2 where you have a spritesheet already made and you want to quickly resize things.

Updated function with feedback from @freds72 and @MBoffin:

function xspr(sprt,x,y,w,h)
    --sprt: sprite number
    --x: x position
    --y: y position
    --w: new sprite width
    --h: new sprite height
    local sx=(sprt%16)*8
    local sy=sprt\16*8
    sspr(sx,sy,8,8,x,y,w,h)
end

Original function:

function xspr(sprt,x,y,w,h)
    --sprt: sprite number
    --x: x position
    --y: y position
    --w: new sprite width
    --h: new sprite height

    local sx=0
    local sy=0
    for i=0,255,16 do
        if(sprt>=i) then
            sy=flr(i/2)
            sx=(sprt-i)*8
        end
    end
    sspr(sx,sy,8,8,x,y,w,h)
end

Probably already exists someplace but thought I'd share my own solution to the problem.

Cheers

P#86188 2021-01-06 00:29 ( Edited 2021-01-06 09:23)

1

the for loop is absolutely not necessary!

local sx=(sprt%16)*8
local sy=flr(sprt/16)*8
P#86195 2021-01-06 06:28

Cheers, that will save tokens

P#86197 2021-01-06 07:01
1

@petpolitics The second line of what @freds72 posted can also be shortened to local sy=sprt\16*8

(Note the \ instead of the / which will do integer division.)

P#86199 2021-01-06 08:32

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 13:21:54 | 0.062s | Q:15