PlayBASIC LIVE: Render (Event) Stacks More Flexible Main Loop (2017-05-28) Welcome... This video looks at alternative ways we can set up the so called 'main loop' in our games in a more flexible fashion. What we can do is separate our rendering / processing / logic code up into a series of events that need to performed to build each frame. You can think of this as a 'to do' or 'job' list. This allows us to change what jobs (and order) need to be performed, as well allowing us to control this externally. So your level editing tool/person can tweak things themselves without the programmer having to hard code every changing into your main loop(s)..
watch on youtube (https://www.youtube.com/watch?v=kfR1hRrdylk) Example: [pbcode]
setfps 20
Dim EventStack(255)
EventStack(10) = 100 ; CLS
EventStack(20) = 200 ; Draw Backdrop
EventStack(30) = 500 ; Draw Sprites
EventStack(40) = 1000 ; Call SYNC
do
For Lp=0 to 255
Select EventStack(lp)
case 100
Event_Cls()
case 200
Event_drawbackdrop()
case 201
Event_drawbackdrop2()
case 500
drawsprites()
case 1000
Event_SYNC()
endselect
next
IF FUNCTIONkEYS(1)
EventStack(25) = 201
ELSE
EventStack(25) = 0
ENDIF
loop
function Event_Cls()
cls rgb(200,0,0)
EndFunction
function Event_Sync()
sync
EndFunction
function Event_drawbackdrop()
shadebox 100,100,700,500,$11223344, $ff00ff, $00ff00,$00ff80
endfunction
function Event_drawbackdrop2()
circleC 0,0,100,true,$445566
endfunction
function drawsprites()
randomize 57
static scrollX
ScrollX=mod(ScrollX-1,800)
for lp =0 to 10
x=scrollX+rnd(800)
y=rnd(600)
col=rndrgb()
circlec x,y,32,true,col
next
endfunction
[/pbcode]
Related To: - Execution Stack Example (http://www.underwaredesign.com/forums/index.php?topic=4282.0)
- Triggers Time Based Model (http://www.underwaredesign.com/forums/index.php?topic=3684.0)
- Abstraction Layer (http://www.underwaredesign.com/forums/index.php?topic=3611.0)
- Timer Based Life Spans (http://www.underwaredesign.com/forums/index.php?topic=3106.0)
- Action GUI (http://www.underwaredesign.com/forums/index.php?topic=3899.0)