Page 1 of 1

OpenWindowedScreen freezes

Posted: Mon Jul 14, 2014 5:39 pm
by ewardd
Hello guys.

My problem is about OpenWindowedScreen. When i run my game at full screen mode, everything works just fine, but when i run it at Windowed Screen it starts as it must. 'NPC's' moving as they made to and etc.

But when i create a 'tower's' (not single one, like after 78 towers created (each tower is 2 sprites -> body and head (head is 3d sprite for rotating)) WindowedScreen like 'freezes' looks like it just stops drawing it at window, because, on example, KeyboardPushed(#PB_Key_Escape) for closing game still works. So my questions are: how can i solove this problem and why it happens? Is there limit on sprites created for WindowedScreen?

P.S. Im using for each tower new 3d and 2d sprite (for rotating each tower's sprite to it's shot target).

P.S.S. Mby i had to write topic at Game Programming? :d

Re: OpenWindowedScreen freezes

Posted: Mon Jul 14, 2014 5:52 pm
by STARGÅTE
ewardd wrote:P.S. Im using for each tower new 3d and 2d sprite (for rotating each tower's sprite to it's shot target).
You don't need for each tower a new sprite.
You can save the rotation in your one variable/structure and set for each tower the new rotation.

But without code we can't help you.

Re: OpenWindowedScreen freezes

Posted: Mon Jul 14, 2014 6:11 pm
by ewardd
Thanks for fast answern. About rotation: i just tried it once again with one sprite and it was sucessful, thanks. Tho i thought i tried it before and it failed... strange. Probably i just did smth wrong that time.

Thats how im creating screen:

Code: Select all

If isWindowed = 0
  If OpenScreen(WINDOW_WIDTH, WINDOW_HEIGHT, 32, GAME_TITLE, 0, 200)
    SetFrameRate(FrameRate)
    FrameLimitInit(GAME_FrameRate/FrameStep)
  Else
    MessageRequester(GAME_TITLE, "Error at creating Game screen")
    End
  EndIf
Else
  If OpenWindow(0, 200, 200, WINDOW_WIDTH, WINDOW_HEIGHT, GAME_TITLE,#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
    If OpenWindowedScreen(WindowID(0), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0)
      SetFrameRate(FrameRate)
      FrameLimitInit(GAME_FrameRate/FrameStep)
    Else
      MessageRequester(GAME_TITLE, "Error at creating Game screen")
      End
    EndIf
  Else
    MessageRequester(GAME_TITLE, "Error at creating Game window")
  EndIf
EndIf
Main loop:

Code: Select all

Repeat
  If IsScreenActive()
    ExamineKeyboard()
    
    If isWindowed
      Repeat
        Event = WindowEvent()
        
        Select Event
          Case #PB_Event_CloseWindow
            Quit = 1
            
        EndSelect
        
      Until Event = 0
    EndIf
    
    FlipBuffers()
    ClearScreen(RGB(0,0,0))
    StartDrawing(ScreenOutput())
    Start3D()
    Sprite3DQuality(#PB_Sprite3D_BilinearFiltering)
    DrawingMode(#PB_2DDrawing_Transparent)
    GetCursorPos_(Mouse) 
    
    DebugGrid()
    UpdateEnemys()
    UpdateTowers()
    UpdateBullets()
    If isWindowed = 0
      SelectedCellX.i = Mouse\x / CellWidth
      SelectedCellY.i = Mouse\y / CellHeight
    Else
      SelectedCellX.i = WindowMouseX(0) / CellWidth
      SelectedCellY.i = WindowMouseY(0) / CellHeight
    EndIf
    
    Box(Mouse\x, Mouse\y, 5, 5)
    LineXY(Mouse\x, Mouse\y, 2*CellWidth+CellHalfWidth+8, 5*CellHeight+CellHalfHeight+8, RGB(0,0, 255))
    
    If isBoxCircleCollision(Mouse\x, Mouse\y, 5, 5, 2*CellWidth+CellHalfWidth+8, 5*CellHeight+CellHalfHeight+8, 50)
      dist = GetDistance(Mouse\x, Mouse\y, 2*CellWidth+CellHalfWidth, 5*CellHeight+CellHalfHeight)
      DrawText(200, 200, "COL: 1| "+Str(dist), RGB(255, 0, 0))
    EndIf
    
    If GetAsyncKeyState_(#VK_LBUTTON) <> 0
      _CellMap(SelectedCellY, SelectedCellX)\BitMask = MASK_FREE
    EndIf
    If KeyboardReleased(#PB_Key_Space) <> 0
      AddEnemy(0, 0, 8, 0)
    EndIf
    If KeyboardPushed(#PB_Key_A)
      CreateMapFile()
      Delay(1000)
    EndIf
    If KeyboardPushed(#PB_Key_B)
      LoadMapFile()
      Delay(1000)
    EndIf
    If KeyboardPushed(#PB_Key_C)
      AddTower(SelectedCellX, SelectedCellY, 1)
      Debug "TowersAM: "+TowersAmout ; <-------- At time we have 78 towers windowedscreen like freezes (stops updating or idk tho main loop still goes same way (counting and etc just image freezes)
      ;Delay(1000)
    EndIf
    If GetAsyncKeyState_(#VK_RBUTTON) <> 0
      _CellMap(SelectedCellY, SelectedCellX)\BitMask = MASK_BUILD
    EndIf
    DrawText(10, 20, "FPS: "+FPS$, RGB(255, 0, 0))
    Stop3D()
    StopDrawing()
    SetSpeedFactor();
    Gosub FPSC
  Else
    Delay(10)
  EndIf
Until KeyboardPushed(#PB_Key_Escape)
Code, at place to place, can be dirty cuz im more testing random ideas, than creating specific game.

Re: OpenWindowedScreen freezes

Posted: Mon Jul 14, 2014 6:19 pm
by STARGÅTE
I think, the merging of Start3D() and StartDrawing() ist the problem!
So change you code to Start3D() : Stop3D() and then StartDrawing() : StopDrawing()

Re: OpenWindowedScreen freezes

Posted: Mon Jul 14, 2014 6:43 pm
by ewardd
Exactly! You was right <3. Thanks you a lot.