Page 1 of 1

Is page flipping the best way to animate?

Posted: Fri Oct 19, 2007 4:26 pm
by Mentat
And when is the best time to insert a flip command in FreeBASIC? I haven't gotten the entire concept down.

Posted: Fri Oct 19, 2007 7:42 pm
by Mac
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

Posted: Fri Oct 19, 2007 8:05 pm
by Mentat
Ohhh... so I work on one while another is displayed? I just used the Screensync command.

So is there some rules of thumb I can use to guess when to Flip? And do I need CLS if I'm using different pages?

Thanks.

Flipping

Posted: Sat Oct 20, 2007 10:22 am
by Mac
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

Posted: Sat Oct 20, 2007 2:12 pm
by Mac
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

Posted: Sun Oct 21, 2007 11:33 am
by Codemss
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.

Posted: Sun Oct 21, 2007 3:25 pm
by Lachie Dazdarian
This is what I do in FreeBASIC:

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)
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.