Here's a couple of fairly simple functions I've been working on to save me some headaches. I thought I'd share them.
Basically you have to initialise a single global variable to allow for both percentage and virtual resolution set-ups.
You can use this to get a position on your sprite in world co-ordinates (even if the sprite is rotated). Here's the code with a sample project (attached with media):
rem
rem AGK Application
rem
rem Landscape App
SetDisplayAspect( 800.0/600.0 )
`setVirtualResolution(800,600)
gosub init_aspect:
setPrintSize(2)
rem load the test sprite images
loadImage(1,"test1.png")
loadImage(2,"test2.png")
rem create sprites
createSprite(1,1)
setSpriteSize(1,w#*0.8,-1)
setSpriteOffset(1,getSpriteWidth(1)/2,getSpriteHeight(1)/2)
setSpritePositionByOffset(1,w#*0.5,h#*0.5)
`
createSprite(2,2)
setSpriteSize(2,w#*0.06,-1)
setSpriteOffset(2,getSpriteWidth(2)/2,getSpriteHeight(2)/2)
rem A baxslash Did It!
do
rem rotate the sprite
setSpriteAngle(1,getSpriteAngle(1)+0.2)
rem position the second sprite
x# = spriteToWorldX(1,-getSpriteWidth(1)*0.25,0)
y# = spriteToWorldY(1,-getSpriteWidth(1)*0.25,0)
setSpritePositionByOffset(2,x#,y#)
Sync()
loop
init_aspect:
global aspect as float
w# = getVirtualWidth()
h# = getVirtualHeight()
if w#=100.0 and h#=100.0
aspect = getDisplayAspect()
else
aspect = 1.0
endif
return
function spriteToWorldX(spr,x#,y#)
a# = getSpriteAngle(spr)
ox# = getSpriteXbyOffset(spr)
dx# = cos(a#) * x# - sin(a#) * y#
wx# = ox# + dx#
endfunction wx#
function spriteToWorldY(spr,x#,y#)
a# = getSpriteAngle(spr)
oy# = getSpriteYbyOffset(spr)
dy# = sin(a#) * x# + cos(a#) * y#
wy# = oy# + dy# * aspect
endfunction wy#
To test virtual resolution / percentage based just remark out the first / second line accordingly. The init sub-routine allows for both types.
EDIT: forgot to attach the project