Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do I need to use CLS?

Status
Not open for further replies.

markh999

Programmer
Aug 4, 2003
10
GB
I'm writing a maze game where you walk through it and looks like 3-d although its only a crude use of the LINE command really. However, evertime I move forward in the maze, I use the CLS command and then redraw all the lines to show the new view. It works but its jerky (i.e. noticeable delay) and looks messy as a result. I've tried redrawing the lines with the background colour (to blank them out) and then redrawing the new view (therefore not using CLS) but this is still jerky.

Any thoughts on how I might make this better? Many thanks.
1st post by the way and a newbie programmer to Qbasic.
 
Use page swapping. Look at the SCREEN statement in QBasic Help's INDEX section. You want to use the <apage> and <vpage>, which allow you to write your graphics to a hidden page, then switch to the page you wrote graphics to. You'll find it makes it smoother because you don't see it draw the lines on the screen.
 
you will also want to look at the PCOPY command

If a man says something in the forest and no woman hears it is he still wrong?
 
or you can write to a buffer. draw your maze to a buffer, then put it on the screen. that'll eliminate any flicker. but since you are using teh line statement, you'll need to make your own, as you can't use the line statement in a buffer. you are familiar with y=mx+b, right? you'll also need to know about memory, poke, segments, offsets... on second thought, maybe you should just stick to some simpler things.

wait &h3da, 8

i try to avoid this, as it greatly slows down programs.

this is also faster.

line (0,0)-(319, 199), bf, 0

 
Try something like this, it uses a Screen 9 page swapping routine

SCREEN 9
SCREEN , , 0, 1 'hides the screen, writing to background
drawmaze
SCREEN , , 1, 0 'switches the screens making the background now visible
x = 1
y = 1
WHILE a% > 1
a% = INP(96) 'keyboard routine
IF a% = 77 THEN
playery% = playery% - 1
ELSEIF a% = 75 THEN playery% = playery% + 1
ELSEIF a% = 80 THEN playerx% = playerx% - 1
ELSEIF a% = 72 THEN playerx% = playerx% + 1
END IF
PCOPY 0, 1 'copies the active screen to the background screen
SCREEN , , 0, 1 'switches so that background in being written to
drawmaze
SCREEN , , 1, 0 ' switches background and foreground again
WEND



If a man says something in the forest and no woman hears it is he still wrong?
 
Many thanks for all the input - I'm experimenting now.
 
You might also want to try simply overwriting the old lines and then drawing the new lines. Like this:

SCREEN 12
LINE (MAZE)-(LINES),RED,B
LINE (MAZE)-(LINES),RED,B
LINE (MAZE)-(LINES),RED,B

[user/computer movement command entered]

LINE (MAZE)-(LINES),BLACK,B
LINE (MAZE)-(LINES),BLACK,B
LINE (MAZE)-(LINES),BLACK,B
LINE (NEW)-(LINES),RED,B
LINE (NEW)-(LINES),RED,B
LINE (NEW)-(LINES),RED,B

This way only the old lines get &quot;eraced&quot; when you are moving through the maze, removing that terrible &quot;flashing&quot; in between movements. More work? Yes, unless you have a program to generate the LINE values:

LINE (A,B)-(C,D),4,B
LINE (A,B)-(C,D),0,B
LINE (E,F)-(G,H),4,B

Like that. A more simple cure if I do say so!

Doug :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top