WindowedScreen question
Posted: Wed Jan 15, 2025 4:15 pm
So, the basic idea for this program is to open a borderless window to the dimensions of the current desktop. This is so I don't have to deal with changing resolutions with a full graphic screen. Then, at some point in the bigger program I would like to have a procedure that I could call that creates a WindowedScreen within the window that will bounce a sprite around the screen. Everything works fine except... while the sprite is moving around the screen, the mouse pointer continually spins without disappearing. Also, if I click a mouse button the program crashes. I'm not as familiar with windowed coding as I'd like to be, and the code is really messy, but if anyone could explain what I;m doing wrong I would be grateful. Thank you.
Code: Select all
ExamineDesktops()
InitSprite()
InitKeyboard()
Global Window_0.i
Procedure OutOfService()
#Font = 0
#Sprite = 0
Define Quit.b = #False
Define ScreenH.i = DesktopHeight(0)
Define ScreenW.i = DesktopWidth(0)
Define Text.s = "Out Of Service"
Define x.i = 1
Define y.i = 1
Define xd.i = 1
Define yd.i = 1
Define SpriteH.i
Define SpriteW.i
Define TWidth.i
Define THeight.i
Define TextFont.i = LoadFont(#Font, "Tahoma", 32, #PB_Font_Bold)
If OpenWindowedScreen(WindowID(Window_0), 0, 0, ScreenW, ScreenH) = 0
End
EndIf
ClearScreen(RGB(0,0,0))
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(Textfont)
DrawText(0, 0, Text, #White, #Black)
TWidth = TextWidth(Text)
THeight = TextHeight(Text)
StopDrawing()
GrabSprite(#Sprite, 0, 0, TWidth, THeight, #PB_Sprite_PixelCollision)
SpriteH = SpriteHeight(#Sprite)
SpriteW = SpriteWidth(#Sprite)
Repeat
ClearScreen(RGB(0, 0, 0))
DisplaySprite(#Sprite, x, y)
x=x+xd:y=y+yd
If y>ScreenH - SpriteH
yd=-1
EndIf
If x>ScreenW - SpriteW
xd=-1
EndIf
If y<0
yd=1
EndIf
If X<0
xd=1
EndIf
FlipBuffers()
ExamineKeyboard()
Delay(1)
Until KeyboardPushed(#PB_Key_Escape)
FreeSprite(#Sprite)
CloseScreen()
EndProcedure
Width = DesktopWidth(0)
Height = DesktopHeight(0)
Depth = DesktopDepth(0)
; Create borderless window with above measurements and black background.
Window_0 = OpenWindow(#PB_Any, 0, 0, Width, Height, "", #PB_Window_BorderLess)
SetWindowColor(Window_0, RGB(0,0,0))
OutOfService()