There seems to be a lot of discussion about code but very little code to back it up. So here's some:
#constant VIRTUAL 0
#constant PECENTAGE 1
type tDisplay
dw as integer
dh as integer
l as integer
t as integer
r as integer
b as integer
w as integer
h as integer
cx as integer
cy as integer
aspect as float
style as integer
endtype
global display as tDisplay
global sprite as integer[19]
initDisplay(VIRTUAL, 600, 600)
//initDisplay(VIRTUAL, 600, 300)
//initDisplay(PECENTAGE, 600, 600)
//initDisplay(PECENTAGE, 600, 300)
initSprites()
c = 0
do
CreateCircle( display.cx, display.cy, sin(c)*display.cy*0.75 )
inc c
sync()
loop
function CreateCircle( x#, y#, r# )
a = 0
for k = 0 to 19
SetSpritePositionByOffset( sprite[k], x# + cos(a)*r#, y#+ sin(a)*r# )
SetSpriteAngle( sprite[k], a+90 )
inc a, 18
next k
endfunction
function initDisplay( style, x#, y# )
display.dw = x#
display.dh = y#
display.aspect = (display.dw*1.0)/(display.dh*1.0)
display.style = style
SetWindowSize( display.dw, display.dh, 0 )
if style = VIRTUAL
SetVirtualResolution( display.dw, display.dh )
else
SetDisplayAspect( display.aspect )
endif
display.l = GetScreenBoundsLeft()
display.r = GetScreenBoundsRight()
display.t = GetScreenBoundsTop()
display.b = GetScreenBoundsBottom()
display.w = display.r - display.l
display.h = display.b - display.t
display.cx = display.w * 0.5
display.cy = display.h * 0.5
SetScissor( display.l, display.t, display.r, display.b )
endfunction
function initSprites()
sprite[0] = CreateSprite( 0 )
if display.style = VIRTUAL
SetSpriteSize( sprite[0], display.dw*0.05, display.dw*0.01 )
else
SetSpriteSize( sprite[0], 5, 1 )
endif
SetSpriteOffset( sprite[0], GetSpriteWidth(sprite[0])*0.5, GetSpriteHeight(sprite[0])*0.5 )
SetSpriteColor( sprite[0], 0, 255, 0, 255 )
for k = 1 to 19
sprite[k] = CloneSprite( sprite[0] )
next k
endfunction
Run that and uncomment one of these lines:
initDisplay(VIRTUAL, 600, 600)
//initDisplay(VIRTUAL, 600, 300)
//initDisplay(PECENTAGE, 600, 600)
//initDisplay(PECENTAGE, 600, 300)
That will run the code in one of four display styles:
1. Square aspect, virtual resolution
2. non-square aspect, virtual resolution
3. Square aspect, percentage based resolution
4. non-square aspect, percentage based resolution
The code draws a circle using sprites and trig and you will get a perfect circle with each style except #4. if you use non-square aspect, percentage based resolution then you need additional maths to "fix the squish".
The display function is a little bulkier than it needs to be for this demo but I just copied it from my standard set up.
AGK V2 user - Tier 1 (mostly)