Set Buffer/Flip in B+
Blitz3D Forums/Blitz3D Beginners Area/Set Buffer/Flip in B+
| ||
I'm still confused about this business of setting back buffer/front buffer/flipping/whatever. Making good progress with the Learn To Program... book, but I don't want to go any further until I absolutely understand this. Here's some code from the book that I had to experiment with (inserting the two 'Flip' commands) until it actually worked. Even then, when you press 'ESCAPE', it opens a new window for the 'Are you sure you want to quit? (Y/N)" bit. So - can someone explain how the buffering/flipping thing works and do I have to 'Flip' every time I print something? I know I'm new and everything, but at the moment it seems like an unnecessary complication that wasn't in Blitz2D or 3D. :) ---------- ;set graphics mode Graphics 640,480 ;set the back buffer or something SetBuffer BackBuffer() ;initialise our "GameInProcess" variable to 1 (TRUE) iGameInProcess=True Repeat ;clear the screen Cls ;write out text Text 270,240,"Hello, Blitz Basic!" Flip ;wait for 250 milliseconds Delay(250) ;clear the screen Cls Flip ;wait for 250 mills Delay(250) ;if the user hits escape If KeyHit(1) Cls ;ask the user if they really want to quit QuitAnswer$=Input$("Really Quit (Y/N)?") ;if the user enters a 'Y' If QuitAnswer$="Y" Or QuitAnswer$="y" ;set our condition flag to False iGameInProcess=False EndIf ;end of if quitanswer$ EndIf ;end of it keyhit(1) Until Not igameinprocess ;end of program End ---------- |
| ||
Ouch, sorry BlitzPlus only supports the Input and Print statements in console mode. Also there is no support for FrontBuffers in BlitzPlus which won't help your confusion adapting the book's code. |
| ||
the point of selecting a buffer is that all drawing operation will occur on that buffer. say you loading in an image, and wanted to draw something to that image, you would set the buffer to the ImageBuffer(ship) draw what you want and set the buffer back to the screen buffer. very handy sometimes. sorry if a wee bit off topic! |
| ||
Flynn, Firstly, as skidracer said, BlitzPlus can't do Input in the graphics window. You have to use something like WaitKey instead: Text 10,10,"Really Quit? (Y/N)" Repeat ; loop until Y or N key = WaitKey() If chr(key)="N" or chr(key)="n" Then Exit ; exit loop If chr(key)="Y" or chr(key)="y" Then iGameinProcess=False Exit ; exit loop End If Forever Secondly, the concept of Flip is that you draw EVERYTHING you want to put on the screen, and then you Flip it. Until you flip it, the screen will not change. (Unless you SetBuffer FrontBuffer() but you don't really want to do that.) The reason we Flip is because of animation. You don't want the user to be able to see the screen in the process of being drawn (even if it only takes 2 milliseconds), it looks unprofessional and flickery. You just want to draw the screen in secret while no one's looking, and then when it's all done you Flip the new frame to the front which is what the user can see on the monitor. |
| ||
Thanks, all. Cyberseth - perfectly explained. I've got it now. :D |