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



1

the for loop is absolutely not necessary!

local sx=(sprt%16)*8
local sy=flr(sprt/16)*8

Cheers, that will save tokens


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.)



[Please log in to post a comment]