I am new to PB and I am trying out some stuff.
The code below displays a small block wich advances every second .
Meanwhile with the buttons the direction of the block can be changed.
Why does it take 2 seconds for the box to react and change direction??
Code: Select all
; ------------------------------------------------------------
;
; sim3
; ------------------------------------------------------------
Global ydirection,xdirection
;;==================================================
Procedure timer(t)
StartTime = ElapsedMilliseconds()
Repeat
ElapsedTime = ElapsedMilliseconds()-StartTime
Event.l = WindowEvent()
If Event = #PB_Event_Gadget
; do the normal application stuff here...
Gadget = EventGadget()
Select Gadget
Case 1
SetGadgetText(4,"north")
ydirection = -10
xdirection=0
Case 2
SetGadgetText(4,"south")
ydirection = 10
xdirection=0
Case 3
SetGadgetText(4,"east")
ydirection = 0
xdirection=10
Case 5
SetGadgetText(4,"west")
ydirection = 0
xdirection=-10
EndSelect
EndIf
If Event = #PB_Event_CloseWindow
End
EndIf
Until ElapsedTime>t
EndProcedure
;==================================================
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Can't open DirectX 7 or later", 0)
End
EndIf
If OpenWindow(0,0,0,610,410,"Sim 3",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(0))
ButtonGadget(1,540, 10,60,20,"north")
ButtonGadget(2,540, 40,60,20,"south")
ButtonGadget(3,540, 70,60,20,"east")
ButtonGadget(5,540, 100,60,20,"west")
TextGadget (4,540,140,60,30,"")
EndIf
If OpenWindowedScreen(WindowID(0),5,5,520,400,0,0,0)
CreateSprite(0,10,10)
If StartDrawing(SpriteOutput(0))
FrontColor(RGB(255,0,100))
Box(0,0,10,10)
StopDrawing()
EndIf
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
y=200
xdirection = 10
ydirection = 0
Repeat
; do the sprite & screen stuff here...
FlipBuffers()
; Clear the screen and draw our sprites
ClearScreen(RGB(0,0,0))
DisplaySprite(0, x, y)
x + xdirection
y + ydirection
timer(1000)
ForEver
End