Quote: "I don't see how that works. There's no loop to move the view in increments. Would you call the function recursively until you get the view moved?"
I would just call this function for every loop I wanted to centre on a particular object. Isn't that the most likely way to use a function to centre on a character?
Example:
VW = getDeviceWidth()
VH = getDeviceHeight()
setVirtualResolution(VW,VH)
rem create a bunch of background sprites
for i=1 to 1000
spr = createSprite(0)
setSpriteSize(spr,random(5,15),random(5,15))
setSpriteAngle(spr,random(0,359))
setSpritePositionByOffset(spr,random(-VW,VW*2),random(-VH,VH*2))
setSpriteDepth(spr,1000)
setSpriteTransparency(spr,0)
next
rem create a centre sprite
spr = createSprite(0)
setSpriteSize(spr,20,20)
setSpritePositionByOffset(spr,VW*0.5,VH*0.5)
setSpriteDepth(spr,100)
setSpriteTransparency(spr,0)
setSpriteColor(spr,255,0,0,255)
do
print(str(getRawLastKey()))
moveX# = (getRawKeyState(39)-getRawKeyState(37))*2
moveY# = (getRawKeyState(40)-getRawKeyState(38))*2
setSpritePositionByOffset(spr,getSpriteXbyOffset(spr)+moveX#,getSpriteYbyOffset(spr)+moveY#)
centreViewOnSprite(spr, 1)
sync()
loop
function centreViewOnSprite(spr as integer, smooth as integer)
tx# = getSpriteXbyOffset(spr)-getVirtualWidth()*0.5
ty# = getSpriteYbyOffset(spr)-getVirtualHeight()*0.5
select smooth
case 0
vx# = tx#
vy# = ty#
endcase
case 1
cx# = getViewOffsetX()
cy# = getViewOffsetY()
dx# = tx#-cx#
dy# = ty#-cy#
vx# = cx#+dx#*0.1
vy# = cy#+dy#*0.1
endcase
endselect
setViewOffset(vx#,vy#)
endfunction
Quote: "Yah, I may have to just center first, and then zoom in."
Clever idea, just reset the view zoom to 1.0, centre the view then set the zoom again (using a centred zoom mode). Now why didn't I think of that!?
this.mess = abs(sin(times#))