Screen scaling in smallbasic :( (litdev)

66 views Asked by At
GraphicsWindow.Width = 1080
GraphicsWindow.Height = 607.5

gw = 1080
gh = 607.5
GraphicsWindow.Left = 0
GraphicsWindow.Top = 0

dw = Desktop.Width
dh = Desktop.Height

WidthMod = dw / gw
HeightMod = dh / gh

newWidth = 1080 * WidthMod
newHeight = 607.5 * HeightMod

distanceWidth = newWidth - gw
distanceHeight = newHeight - gh

 LDGraphicsWindow.Reposition(WidthMod, HeightMod, distanceWidth / 2, distanceHeight / 1.3, 0)

The reposition command has the syntax: reposition(scaleX, scaleY, panX, panY, angle).
I do not understand why dividing the distanceWidth (this is the difference between the old screen and the new screen's size) by 2 or dividing the distanceHeight by 1.3 pans the game to the topmost corner where I need it. I want to pan it so that the game has the same view only dependent on a 16:9 ratio.

1

There are 1 answers

2
Zock77 On

LDGraphicsWindow.Reposition doesn't actually move or scale the window at all, it just moves all the shapes inside the window. It's probably not what you're looking for.

If you're just trying to create and center the largest GraphicsWindow for a given aspect ratio, that can easily be done with pretty standard code:

textRatio = "16:9"

ratioArr = LDText.Split(textRatio, ":")

ratio = ratioArr[1] / ratioArr[2] ' Get the numerical ratio from the text
curRatio = Desktop.Width/Desktop.Height ' Get the current ratio

GraphicsWindow.Show()

If curRatio > ratio Then 'Screen is too wide
  GraphicsWindow.Width = Desktop.Height * ratio
  GraphicsWindow.Height = Desktop.Height
ElseIf curRatio < ratio Then 'Screen is too tall
  GraphicsWindow.Height = Desktop.Width / ratio
  GraphicsWindow.Width = Desktop.Width
EndIf

'Center the window
GraphicsWindow.Left = (Desktop.Width/2)-(GraphicsWindow.Width/2)
GraphicsWindow.Top = (Desktop.Height/2)-(GraphicsWindow.Height/2)