AppGameKit lacks the ability to "Lock Mouse to Screen" for when in Windowed Mode
I also couldn't see any examples (but then the Search is a bit 'meh' for these boards)
It's not perfect., but this will allow you "Lock" the Mouse to the Screen
Will continue to work and improve this... as switching between modes isn't seamless.
I also add functions for the Sprite Support (for Animated Sprites)
Other than that Mouse.Position.X/Y is the Window Position, Mouse.Movement.X/Y will tell you how much the Mouse moved since the last call
These two features should make using AppGameKit in Window Mode MUCH easier for Games, such-as Mouse Look.
#Constant True -1
#Constant False 0
#Constant Enable 1
#Constant Disable 0
Type Vec2
X As Float
Y As Float
EndType
Function Vec2( X As Float, Y As Float )
Out As Vec2
Out.X = X
Out.Y = Y
EndFunction Out
Type MouseInfo
Position As Vec2
Movement As Vec2
Visible As Integer
ScreenLock As Integer
Cursor As Integer
CursorFile As String
EndType
Global Mouse As MouseInfo
Function SyncMouse()
Local New As Vec2
Local Screen As Vec2
SetRawMouseVisible( Disable )
// We Assume IF the Mouse Cursor isn't Loaded
// It is a "First Instance" .. might add a flag for this
If Not( GetSpriteExists( Mouse.Cursor ) )
Mouse.Position.X = GetRawMouseX()
Mouse.Position.Y = GetRawMouseY()
Mouse.ScreenLock = True
Mouse.Visible = True
If Len( Mouse.CursorFile )
Mouse.Cursor = CreateSprite( LoadImage( Mouse.CursorFile ) )
Else
Mouse.Cursor = CreateSprite( LoadImage( "Default_Cursor.png" ) )
EndIf
SetSpritePhysicsOff( Mouse.Cursor )
SetSpriteDepth( Mouse.Cursor, 0 )
EndIf
If Mouse.Visible
If Not( GetSpriteVisible( Mouse.Cursor ) ) Then SetSpriteVisible( Mouse.Cursor, Enable )
Else
If GetSpriteVisible( Mouse.Cursor ) Then SetSpriteVisible( Mouse.Cursor, Disable )
EndIf
Screen = Vec2( GetWindowWidth() * 0.5, GetWindowHeight() * 0.5 )
// Get how far the Mouse has moved this frame
New.X = GetRawMouseX() - Screen.X
New.Y = GetRawMouseY() - Screen.Y
// We don't _actually_ use the Raw Mouse Position, so reset to the centre of the screen
If Mouse.ScreenLock
SetRawMousePosition( Screen.X, Screen.Y )
Mouse.Position.X = Mouse.Position.X + New.X
If Mouse.Position.X < 0 Then Mouse.Position.X = 0
If Mouse.Position.X > GetWindowWidth() Then Mouse.Position.X = GetWindowWidth()
Mouse.Position.Y = Mouse.Position.Y + New.Y
If Mouse.Position.Y < 0 Then Mouse.Position.Y = 0
If Mouse.Position.Y > GetWindowHeight() Then Mouse.Position.Y = GetWindowHeight()
Mouse.Movement.X = New.X
Mouse.Movement.Y = New.Y
Else
Mouse.Movement.X = Mouse.Position.X - GetRawMouseX()
Mouse.Movement.Y = Mouse.Position.Y - GetRawMouseY()
Mouse.Position.X = GetRawMouseX()
Mouse.Position.Y = GetRawMouseY()
EndIf
SetSpritePosition( Mouse.Cursor, Mouse.Position.X, Mouse.Position.Y )
EndFunction