Is page flipping the best way to animate?
Is page flipping the best way to animate?
And when is the best time to insert a flip command in FreeBASIC? I haven't gotten the entire concept down.
For any grievances posted above, I blame whoever is in charge . . .
Well, the concept is this
While the user is looking at screen 1, you are doing PRINT and PSET or whatever to screen 2 which does not bother the user. When you are all finished, then on some speed that you decide yourself after experimenting, you swap screens.
Only works on some SCREENs. If not supported, you tend to get flicker which can be minimized by effective use of WAIT &H3DA, 8:WAIT &H3DA, 8,8 commands.
Mac
While the user is looking at screen 1, you are doing PRINT and PSET or whatever to screen 2 which does not bother the user. When you are all finished, then on some speed that you decide yourself after experimenting, you swap screens.
Only works on some SCREENs. If not supported, you tend to get flicker which can be minimized by effective use of WAIT &H3DA, 8:WAIT &H3DA, 8,8 commands.
Mac
Flipping
Run the study below to ensure we are talking the same language here.
In sprite-animation type stuff, you write on one screen while the other is being seen. You flip when you are finished moving stuff.
Some people just use paging to show a help file and return to the game.
Try some sample studies of your own to get the idea.
' Study of SCREEN , , {Program writes here} , {User sees this}
' Program starts with default SCREEN ,,0,0
PRINT : PRINT
PRINT "We start off on page zero (0)"
LINE INPUT "Enter some stuff: "; e$
e$ = CHR$(34) + e$ + CHR$(34)
PRINT "OK - "; e$; " was written on page 0"
SCREEN , , 1, 0: CLS
PRINT "This was written on a nice clean page 1"
WHILE INKEY$ = "": WEND ' User does not see page 1 yet
SCREEN , , 0, 1: CLS
PRINT "This was written on a nice clean page 0"
WHILE INKEY$ = "": WEND ' User sees page 1 now
SCREEN , , 1, 0: PRINT "More for page 1"
WHILE INKEY$ = "": WEND
SCREEN , , 0, 1: PRINT "More for page 0"
WHILE INKEY$ = "": WEND
SCREEN , , 1, 0: PRINT "Even more for page 1"
WHILE INKEY$ = "": WEND
SCREEN , , 1, 1
PRINT "Finished with user currently on page 1"
PRINT "But when QBasic returns to DOS, we return to 0,0"
WHILE INKEY$ = "": WEND
SYSTEM
In sprite-animation type stuff, you write on one screen while the other is being seen. You flip when you are finished moving stuff.
Some people just use paging to show a help file and return to the game.
Try some sample studies of your own to get the idea.
' Study of SCREEN , , {Program writes here} , {User sees this}
' Program starts with default SCREEN ,,0,0
PRINT : PRINT
PRINT "We start off on page zero (0)"
LINE INPUT "Enter some stuff: "; e$
e$ = CHR$(34) + e$ + CHR$(34)
PRINT "OK - "; e$; " was written on page 0"
SCREEN , , 1, 0: CLS
PRINT "This was written on a nice clean page 1"
WHILE INKEY$ = "": WEND ' User does not see page 1 yet
SCREEN , , 0, 1: CLS
PRINT "This was written on a nice clean page 0"
WHILE INKEY$ = "": WEND ' User sees page 1 now
SCREEN , , 1, 0: PRINT "More for page 1"
WHILE INKEY$ = "": WEND
SCREEN , , 0, 1: PRINT "More for page 0"
WHILE INKEY$ = "": WEND
SCREEN , , 1, 0: PRINT "Even more for page 1"
WHILE INKEY$ = "": WEND
SCREEN , , 1, 1
PRINT "Finished with user currently on page 1"
PRINT "But when QBasic returns to DOS, we return to 0,0"
WHILE INKEY$ = "": WEND
SYSTEM
Actually, I have never used page swapping for animation, probably because I don't do animation except for moving sprites around a screen. For simply moving sprites, it is probably best to simply do
WAIT &H3DA, 8
erase old sprite
write new sprite
WAIT &H3DA, 8,8
The only time I use page swapping is for help screens, etc. like
http://www.network54.com/Forum/190883/m ... 1192907116
Mac
WAIT &H3DA, 8
erase old sprite
write new sprite
WAIT &H3DA, 8,8
The only time I use page swapping is for help screens, etc. like
http://www.network54.com/Forum/190883/m ... 1192907116
Mac
- Codemss
- Veteran
- Posts: 124
- Joined: Sun Jun 24, 2007 6:49 am
- Location: Utrecht, The Netherlands
- Contact:
I always do screen flipping with a buffer, and then you PUT it to the screen. This way you can write to the buffer with POKE, which is faster then PSET. It is also possible in SCREEN 13, where page flipping isn't built-in.
And I think that page flipping is the best way to animate and eliminate flicker in any graphical program.
And I think that page flipping is the best way to animate and eliminate flicker in any graphical program.
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
-
- Veteran
- Posts: 202
- Joined: Mon Aug 30, 2004 6:18 am
- Location: Croatia
- Contact:
This is what I do in FreeBASIC:
You are supposed to create your own frame limiter, althought I can show you what I use.
Not sure if page flipping is needed for animation in FB, though. This is just a standard way to handle loops in FB. Some people don't even use page flipping (only screenlock and screenunlock), but if you will use fade in/ fade out effects, this alone might not be enough.
Code: Select all
DO
screenlock ' Lock our screen (nothing will be
' displayed until we unlock the screen).
screenset workpage, workpage xor 1 ' Swap work pages.
CLS
' Our graphics code goes in here.
workpage xor = 1 ' Swap work pages.
screenunlock ' Unlock the page to display what has been drawn.
SLEEP 10, 1 ' Slow down the program and prevent 100 % CPU usage.
LOOP UNTIL MULTIKEY(SC_Q) OR MULTIKEY(SC_ESCAPE)
Not sure if page flipping is needed for animation in FB, though. This is just a standard way to handle loops in FB. Some people don't even use page flipping (only screenlock and screenunlock), but if you will use fade in/ fade out effects, this alone might not be enough.
Lachie Dazdarian - The Maker Of Stuff