INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Graphical Techniques in QB
What are some useful graphic techniques in QB?
Posted: 21 Jun 00
Ahhh yes, Graphics, essential in most QBasic games. Now, QB for some reason just isn't too good at handleing graphics, Leaveing you mostly with slow drawing functions, circles,lines and points. Good thing there are ways around this.
1> Sprite can make you a better programmer...
Sprite graphics load up much faster then simple point to point line drawing, and is much certainly faster then Draw strings (Which I was never fond of in the first place). Sprite style graphics also tend to be much more detailed then anything else you may conjure up. The thing is, drawing a sprite graphic with dots at a usefull speed. Fortunatly for us, QB uses arrays to store many values to one variable.
' Set screen mode
' Ok, First, we'll draw a circle...
Circle (5, 5),5
' Next we set our array up by dimming lotsa numbers to one
DIM test (10 * 10) 'or 10 by 10 graphic
' then we put the graphic into the array we just made
GET (0,0)-(10, 10), test
' ok, its that simple, TEST is now a sprite and we can put
' it anywhere.
put (100, 100),test
Note that the graphic will not be centered on 100, 100 coordinates... instead, it uses the upper left corner (where it started reading the varable) as it's 'x,y'
that about does it for sprite graphics...
2> pixel by pixel rendering
Next process in makeing a decent sprite is to render it pixel by pixel, this is done by reading data for each color of each point. It CAN be read from a seperate file, but for genral pourpuses of this FAQ, I'm useing data statements. Also note, I put my data statements at the end of my program, I don't know why, Perhaps its a habit...
' assumeing you're programming on the end of that last part
' 10 by 10 sprite
for y = 1 to 10
for x = 1 to 10
read a 'Reads numarical data
pset (x, y) , a 'paints a pixel the color designated
dim test1 (10 * 10) 'Dim it!
get (0,0)-(10, 10), test1 'Get it!
' you now have a crasshair
put (100, 100) test1
' and a circle
put (110, 100) test
' Your data staements, Each number refers to a color value
' This perticular string draws a nifty crosshair
That's pretty cool huh? simple to use too.
3> Mmmmmmm.... page flipping...
Tired of flicker? wish you could see you're graphics all the time? Wish no longer, page flipping creates a smooth and fast way to compleatly eliminate flicker from redraw.
the example below assumes you already have both above graphics dim'ed up to memory.
'first, we enter a new screen mode...
' this sets up the following:
' Screen 7 (320/200 pixels)
' Visible page is 0
' write page is 1, and remains unseeable
' copy to page is 0
' Now, we flip
' begin by starting a loop, this one will end at a keypress
' just a little geometry handeler...
if xm = 0 the x = x + 1, if x > 300 then xm = 1
if xm = 1 the x = x - 1, if x > 2 then xm = 0
if ym = 0 the y = y + 1, if y > 300 then ym = 1
if ym = 1 the y = y - 1, if y > 2 then ym = 0
' put you're graphic somewhere... preferable x and y
put (x, y), test1
' and here's the madd page flip:
pcopy 1, 0
' We just copied the contents of screen 1 to screen 0
' Clear the invisible screen..
' loop that motha...
loop while inkey$ = ""
END OF EXAMPLE
Its that simple.
4> Zooming (oooooo... yeah)
This is a new technique i came up with, I whipped it up in about 10 minutes, and is direct scorce of how to zoom a sprite, at the time of this post, it had been run once. This code has no relation to the abouve code...
warning: This code has been modified from it's original version, it has bneen formatted to fit this box... Also, note that I will just give you the routine, I'm not gonna show you how to use it effectivly. At this point that's for you to figure out. Call it a challenge...Here it is:
CIRCLE (5, 5), 5
FOR a = 2 TO 10
FOR d = 0 TO 10
FOR dd = 0 TO 10
FOR dx = 0 TO a
FOR dy = 0 TO a
PSET ((10 + (a * 10)) + ((dd * a) + dx) --cont. next line--
, (d * a) + dy), POINT(dd, d)
END OF EXAMPLE
Have fun with that, I know I will.
Well, That concludes my graphics fAQ... I hope to have inspired at least one person.
Back to QBasic FAQ Index
Back to QBasic Forum