Problem found... how to make a counter in games?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by duschman.
I found the problem with the thread.
It seems that it needs an extra OpenScreen()
in the thread function. But thats really stupid
because I just nead a small area where the counter is
diplayed.
So how do I make a counter in purebasic running in the back
of the programm and doesn't slow down my
other parts of the program?
THX for comments
Martin Strojek
I found the problem with the thread.
It seems that it needs an extra OpenScreen()
in the thread function. But thats really stupid
because I just nead a small area where the counter is
diplayed.
So how do I make a counter in purebasic running in the back
of the programm and doesn't slow down my
other parts of the program?
THX for comments
Martin Strojek
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Berikco.
I never used the DX stuff before, here is my first attempt
Regards,
Berikco
http://www.benny.zeb.be
I never used the DX stuff before, here is my first attempt
Code: Select all
Global counter
counter=60
Procedure myCallback(WindowID, Message, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select Message
Case #WM_TIMER
Select wParam
Case 1 ; timer number 1
beep_(500,50)
counter-1
result=0
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
Procedure KeyCheck()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
End
EndIf
EndProcedure
hwnd=OpenWindow(0,100,350,400,400, #PB_Window_Invisible ,"testing")
If hwnd
SetWindowCallback(@MyCallback())
SetTimer_(hWnd,1,1000,0) ; 1 sec timer
If InitSprite() = 0
MessageRequester("Error!","InitSprite failed!",0)
End
EndIf
If InitKeyboard()=0
MessageRequester("Error!","InitKeyboard failed!",0)
End
EndIf
If OpenScreen(800,600,32,"counter") = 0
MessageRequester("Error","OpenScreen failed!",0)
End
EndIf
Repeat
WindowEvent()
FlipBuffers()
ClearScreen(0,0,0)
KeyCheck()
If StartDrawing(ScreenOutput())
Locate(700, 20)
DrawText("Time:"+Str(counter))
StopDrawing()
EndIf
ForEver
CloseScreen()
EndIf
Berikco
http://www.benny.zeb.be
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
In September I sent you a personal email to AlphaSND regarding problems with Threads, Sprites, and OpenWindowedScreen specially under WinXP - and NEVER got an answer.
I wasted a lot of time searching for a bug (and didn't found one...).
Now this statement of yours.
Thanks.

BTW: It was not a simple counter...
@FredOriginally posted by fred
PB graphics functions are not safe when used in thread (I don't know if DX one are safe), and using thread to display gfx, is IHMO not a good idea. To get a counter, just put it in your main loop..
Fred - AlphaSND
In September I sent you a personal email to AlphaSND regarding problems with Threads, Sprites, and OpenWindowedScreen specially under WinXP - and NEVER got an answer.
I wasted a lot of time searching for a bug (and didn't found one...).
Now this statement of yours.
Thanks.
BTW: It was not a simple counter...
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
Fred - AlphaSND
Sorry, I should have skipped it..Originally posted by Franco
In September I sent you a personal email to AlphaSND regarding problems with Threads, Sprites, and OpenWindowedScreen specially under WinXP - and NEVER got an answer.
I wasted a lot of time searching for a bug (and didn't found one...).
Now this statement of yours.
Thanks.
![]()
![]()
![]()
BTW: It was not a simple counter...
Fred - AlphaSND
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by MrVainSCL.
hi duschman
sorry i dont really understand your posting... if you need an area for displaying any stuff like your counter while coding/debugging i.e. you can print it to your gamescreen with DrawText() for example... If you want just only see the vals in an seperate window for testing, run your game (screen) in WinowedMode and print the counter stuff in an console with OpenConsole for example...
If you need a counter for something in the background, just use it in your mainloop... So you can
count your value but its still hidden for the user...
Hi Berikco and Fred
TimeGetTime_() is more exact as GetTickCount_() !! So you should better use TimeGetTime() for any internal counters... If you want move any objects in same speed on all PCs (based on timer and fps independent instead of setting a fixed fps) you should take a look to the tips and tricks section where i posed a small example how to move objects in same speed on all PCs but fps independent...
PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
hi duschman
sorry i dont really understand your posting... if you need an area for displaying any stuff like your counter while coding/debugging i.e. you can print it to your gamescreen with DrawText() for example... If you want just only see the vals in an seperate window for testing, run your game (screen) in WinowedMode and print the counter stuff in an console with OpenConsole for example...
If you need a counter for something in the background, just use it in your mainloop... So you can
count your value but its still hidden for the user...
Hi Berikco and Fred
TimeGetTime_() is more exact as GetTickCount_() !! So you should better use TimeGetTime() for any internal counters... If you want move any objects in same speed on all PCs (based on timer and fps independent instead of setting a fixed fps) you should take a look to the tips and tricks section where i posed a small example how to move objects in same speed on all PCs but fps independent...
PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...
greetz
MrVainSCL! aka Thorsten
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> TimeGetTime_() is more exact as GetTickCount_()
True, but it's almost 8 times slower than using GetTickCount_():
http://www.mvps.org/directx/articles/se ... ctions.htm
> TimeGetTime_() is more exact as GetTickCount_()
True, but it's almost 8 times slower than using GetTickCount_():
http://www.mvps.org/directx/articles/se ... ctions.htm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
This is using a high resolution timer.
The Timer is running in its own thread.
Dont use DirectX functions in threads, only
change variables, and check the variables in
your game-loop.
cya,
...Danilo
(registered PureBasic user)
Code: Select all
Procedure ColorChanger()
Shared color, colorflag, counter
If colorflag = 0
color + 10
If color => 255 : color = 255 : colorflag = 1 : EndIf
Else
color - 3
If color <= 20 : color = 20 : colorflag = 0 : EndIf
EndIf
counter + 1
EndProcedure
Procedure KeyCheck()
If KeyboardPushed(#PB_Key_Escape)
End
EndIf
EndProcedure
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("ERROR","Cant initialize DirectX!",0) : End
EndIf
#SCREENNAME.s = "TEST"
If OpenScreen(800,600,32,#SCREENNAME) = 0
If OpenScreen(800,600,24,#SCREENNAME) = 0
If OpenScreen(800,600,16,#SCREENNAME) = 0
MessageRequester("ERROR","Cant open Screen!",0) : End
EndIf:EndIf:EndIf
StartTimer(1,40,@ColorChanger())
Repeat
FlipBuffers()
ExamineKeyboard()
If IsScreenActive()
ClearScreen(0,0,0)
KeyCheck()
ExamineMouse()
hDC = StartDrawing(ScreenOutput())
Locate(MouseX(),MouseY())
DrawingMode(1)
FrontColor(color,color,color)
DrawText("PureBasic")
Locate(350,20)
FrontColor($FF,$FF,color)
DrawText("Counter: "+StrU(counter,2))
StopDrawing()
Else
Delay(10)
EndIf
ForEverThe Timer is running in its own thread.
Dont use DirectX functions in threads, only
change variables, and check the variables in
your game-loop.
cya,
...Danilo
(registered PureBasic user)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by duschman.
Hi all,
thanks for your comments. Maybe it helps if I say
what I'm trying to do:
I want to convert a C64 game and for solving the game
you have just a little time. The first thing, my counter isn't
just a text but some sprite for each digit of the actual counter.
So I swap my counter value into digits and load sprite for the numbers. But thats not the problem, it works fine.
I just wanted to be sure that the timer is running completely in the back and all other would be handled from the main loop of the program.
I don't know if there's a problem counting in the main loop, but I wanted to be sure that the counter will run independent. I use some delays of about 20 because I have to slow down moving some time to have a good speed for gameplay. So that would slow down my timer, too.
Hi all,
thanks for your comments. Maybe it helps if I say
what I'm trying to do:
I want to convert a C64 game and for solving the game
you have just a little time. The first thing, my counter isn't
just a text but some sprite for each digit of the actual counter.
So I swap my counter value into digits and load sprite for the numbers. But thats not the problem, it works fine.
I just wanted to be sure that the timer is running completely in the back and all other would be handled from the main loop of the program.
I don't know if there's a problem counting in the main loop, but I wanted to be sure that the counter will run independent. I use some delays of about 20 because I have to slow down moving some time to have a good speed for gameplay. So that would slow down my timer, too.