It's like
setSpriteScissor except the coordinates for the clipping are local to the sprite. The cool thing about it is, the clipping rotates with the sprite. I had some other cool ideas in mind, but I'd need a way to rotate the sprite's UV.
It's a code snippet, but I couldn't quite get it to work perfectly so I posted here instead. I just couldn't work out how to properly manage the XY coordinates for positioning without storing additional variables, and I wanted the function to be self contained. But it's something at least, so here's a demo.
r = createSmartSprite("covers/crank.jpg")
x = 142
y = 230
setSpriteSmartPosition(r, x, y)
x1 = 0
y1 = 0
x2 = getImageWidth(getSpriteImageID(r))
y2 = getImageHeight(getSpriteImageID(r))
delay = 5
Repeat
ms = getMilliseconds()
if timestamp+delay <= ms
if grow = 1
dec x1
x2 = getImageWidth(getSpriteImageID(r)) - x1
y1 = x1
y2 = getImageHeight(getSpriteImageID(r)) - x1
if x1 <= 0
x1 = 0
grow = 0
endif
else
inc x1
x2 = getImageWidth(getSpriteImageID(r)) - x1
y1 = x1
y2 = getImageHeight(getSpriteImageID(r)) - x1
if x1 >= 150
grow = 1
endif
endif
setSpriteSmartClip(r, x1, y1, x2, y2)
setSpriteSmartPosition(r, x, y)
timestamp = ms
endif
if getRawMouseLeftPressed() = 1 and getRawKeyState(16)=1
y1 = getRawMouseY()
setSpriteSmartClip(r, x1, y1, x2, y2)
endif
if getRawMouseRightPressed() = 1 and getRawKeyState(16)=1
y2 = getRawMouseY()
setSpriteSmartClip(r, x1, y1, x2, y2)
endif
if getRawMouseLeftPressed() = 1 and getRawKeyState(16)=0
x1 = getRawMouseX()
setSpriteSmartClip(r, x1, y1, x2, y2)
endif
if getRawMouseRightPressed() = 1 and getRawKeyState(16)=0
x2 = getRawMouseX()
setSpriteSmartClip(r, x1, y1, x2, y2)
endif
if getRawKeyPressed(32)=1 then resetSpriteUV(r)
inc a
if a >= 360 then a = 0
setSpriteAngle(r, a)
if getRawKeyState(39) = 1
inc x
setSpriteSmartPosition(r, x, y)
endif
if getRawKeyState(37) = 1
dec x
setSpriteSmartPosition(r, x, y)
endif
Sync()
Until getRawKeyPressed(27)=1
end
function createSmartSprite(path$)
i = loadImage(path$)
setImageWrapU(i, 1)
setImageWrapV(i, 1)
s = createSprite(i)
setSpriteOffset(s, 0, 0)
endfunction s
function setSpriteSmartClip(s, x1, y1, x2, y2)
width = x2-x1
height = y2-y1
setSpritesize(s, width, height)
img = getSpriteImageID(s)
w# = getImageWidth(img)
h# = getImageHeight(img)
u1# = x1 / w#
u2# = x2 / w#
v1# = y1 / h#
v2# = y2 / h#
setSpriteUV(s, u1#,v1#, u1#,v2#, u2#,v1#, u2#,v2#)
setSpriteOffset(s, x1, y1)
setSpritePosition(s, x1, y1)
endfunction
function setSpriteSmartPosition(s, x, y)
x1 = getSpriteX(s) - getSpriteXByOffset(s)
y1 = getSpriteY(s) - getSpriteYByOffset(s)
setSpritePosition(s, x-x1, y-y1)
setSpriteOffset(s, getSpriteWidth(s)/2, getSpriteHeight(s)/2)
endfunction
"I like offending people, because I think people who get offended should be offended." - Linus Torvalds