problem when losing focus...
-
Brice Manuel
problem when losing focus...
I am porting a windowed game I had started in IBasic and I ran into a snag. Anytime it loses focus, the screen goes white. I thought it was my shoddy programming, but then I tried the "Lady" game by Paul and the same problem happens with "Lady". What can I do to prevent this?
-
Brice Manuel
umm... No, I don't. And I am not sure how to properly use them (still somewhat new to PB.
Here is the main loop for Lady's Garden, which exhibits the same problem as my game. Is there any chance you could show me how to properly fix this so it doesn't become corrupted when the window loses focus?
Thank you in advance for any help.
Here is the main loop for Lady's Garden, which exhibits the same problem as my game. Is there any chance you could show me how to properly fix this so it doesn't become corrupted when the window loses focus?
Code: Select all
;--------------------
;-MAINLOOP
mainloop:
Gosub init_data
Gosub load_maze
Gosub load_data
If level=1 And bugs=1
hold=0
While hold=0
DisplaySprite(4,0,0)
text(80,90,"GUIDE BUMBLE THROUGH")
text(80,115,"THE HEDGE MAZE AND")
text(80,140,"PICK ALL THE FLOWERS")
text(80,215,"IF LADY CATCHES YOU")
text(80,240,"ITS GAME OVER")
text(130,350,"PRESS SPACEBAR")
frmbee=frmbee+1
If frmbee>9:frmbee=0:EndIf
DisplayTransparentSprite(frmbee+50,30,90)
DisplayTransparentSprite(8,30,220)
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space) Or KeyboardPushed(#PB_Key_Escape):hold=1:EndIf
Wend
EndIf
If useAudio:PlaySound(4):EndIf
While quit=0
If flower=0:quit=1:EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape):Gosub draw_credits:End:EndIf
If KeyboardPushed(#PB_Key_Left):mm=1:EndIf
If KeyboardPushed(#PB_Key_Right):mm=2:EndIf
If KeyboardPushed(#PB_Key_Up):mm=3:EndIf
If KeyboardPushed(#PB_Key_Down):mm=4:EndIf
Select mm
Case 1
If mve=0 And maze(cpxpos-1,cpypos)>2
cx=-2:cy=0:cpdir=1:cpxpos=cpxpos-1:mve=32
Gosub check_flower
EndIf
Case 2
If mve=0 And maze(cpxpos+1,cpypos)>2
cx=2:cy=0:cpdir=3:cpxpos=cpxpos+1:mve=32
Gosub check_flower
EndIf
Case 3
If mve=0 And maze(cpxpos,cpypos-1)>2
cx=0:cy=-2:cpdir=2:cpypos=cpypos-1:mve=32
Gosub check_flower
EndIf
Case 4
If mve=0 And maze(cpxpos,cpypos+1)>2
cx=0:cy=2:cpdir=4:cpypos=cpypos+1:mve=32
Gosub check_flower
EndIf
EndSelect
If mve<>0:cpx=cpx+cx:cpy=cpy+cy:mve=mve-2:EndIf
Gosub move_lady
Gosub draw_board
Gosub draw_bugs
Gosub set_score
If quit>0
If quit=1
tmpy=480
If useAudio:PlaySound(3):EndIf
For nextlevel=0 To 190
Gosub draw_board
Gosub set_score
DisplaySprite(10,134,tmpy)
FlipBuffers()
tmpy=tmpy-3
Next
EndIf
If quit=2:If useAudio:PlaySound(2):EndIf:EndIf
EndIf
FlipBuffers()
Wend
If quit=2
diz=0
Restore level1
For hold=1 To 400
Gosub draw_board
Gosub set_score
Gosub draw_diz
DisplaySprite(11,134,110)
Delay(50)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Space):hold=400:Delay(500):EndIf
If KeyboardPushed(#PB_Key_Escape)
Gosub draw_credits
End
EndIf
FlipBuffers()
Next
level=0
bugs=0
score=0
EndIf
level=level+1
bugs=bugs+1
If bugs>4:bugs=4:EndIf
If level>4:level=1:Restore level1:EndIf
Goto mainloopTry putting
after the line
and most people put a small delay e.g.
after the
The WindowEvent() line processes window messages so events like dragging the window are handled. You can also get the result of WindowEvent() e.g. event = WindowEvent() and respond to windows events (e.g. if the close button has been clicked you could quit your game).
The delay is recommended to prevent the loop from using all the CPU so your desktop should be a little more responsive with that in place.
Code: Select all
WindowEvent()Code: Select all
While quit=0Code: Select all
Delay(5)Code: Select all
FlipBuffers()The delay is recommended to prevent the loop from using all the CPU so your desktop should be a little more responsive with that in place.
Mat
