Fullscreen Games (Help for Beginners)

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Hello !!

Many Beginners want to write Fullscreen games
with PureBasic, but often it doesnt work,
even if the code looks right.
The program crashes without warning and the
programmer gets frustrated...

Here are 3 points you have to care about:

1.) If you use the Screen Commands, you have
to call InitSprite() first -
even if you dont use Sprites !!
The Screen-commands are in the same
Library and dont work if you dont
initialize it.

2.) You can only use the 2D Drawing Commands
within the commands StartDrawing() and
StopDrawing() - look at my example.

3.) Set a FrontColour(R,G,B) if you
want to see something... :wink:

HTH,
...Danilo

Code: Select all

;-------------------------
;   INIT
;-------------------------

If InitSprite() = 0
 MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
  End
EndIf

If InitKeyboard() = 0
MessageRequester("Error","Can't open DirectX 7 Or later",0)
End
EndIf

If OpenScreen(1024, 768, 32, "Sprite")
   Goto StartGame
Else
  MessageRequester("Error", "Can't open screen !", 0)
EndIf
End

;-------------------------
;   Game-LOOP
;-------------------------
StartGame:


Repeat

    FlipBuffers()
    ClearScreen(0,0,0)

    StartDrawing(ScreenOutput())      ; Start 2D-drawing
    FrontColour(255,255,0)
    Box(10,10,100,100)
    Line(200,200,200,200)
    StopDrawing()                     ; End 2D-Drawing


    ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)     ; If ESCAPE is pressed: END
   End
EndIf

     
ForEver