Qbasicnews.com

Full Version: get, put and TRANSPARENCIES!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey all, it crane agian...

You guys are really good about advice and I appreciate it. I was wondering....I am using get and put to animate my "spaceship" in this game i am making. My problem: I draw from an array and every 0 that comes through draws as black. Can I make this transparent? Let me know and thanks!

Charles A. Crane

P.S. I spend every day after work working on this now and I love it! I have not played with QB since I was 8! Thanks all for helping me get back starting, its so much fun!
use a library Smile
Whoa! Ok, I am renaming this thread. What is a LIBRARY??!
A library is a set of functions and routines you can use in your program. They are usually very helpful and very fast. If you're making a game, you should try out UGL. Although it might be a little complicated for you if you don't know what a library is, so I recommend starting off with DirectQB or CosmoX or something crappier than UGL like those... Then once you get used to it, move on to UGL, because all others suck Smile

Anyways, these libraries include functions that resemble Qbasic's PUT and GET functions, which makes them easy to use.

And AOL sucks too. I wish they'd die and burn in hell for all eternity starting NOW.
You don't have to use a library. You can achieve transparency easily enough with a mask:

Code:
DEFINT A-Z

SCREEN 13
DIM SpriteImage(129)
DIM SpriteMask(129)
DIM SaveBackground(129)

'Create the sprite
LINE (0, 0)-(15, 15), 255, BF
CIRCLE (8, 8), 7, 4, , , .83
PAINT (8, 8), 4
CIRCLE (10, 7), 2, 12, , , .83
PAINT (10, 7), 12
GET (0, 0)-(15, 15), SpriteImage(0)

'Create the mask from the sprite
FOR y = 0 TO 15
  FOR x = 0 TO 15
    IF POINT(x, y) = 255 THEN
      PSET (x + 16, y), 0
    ELSE
      PSET (x + 16, y), 255
    END IF
  NEXT
NEXT
GET (16, 0)-(31, 15), SpriteMask(0)

CLS

'Draw some shiznit on the screen
FOR x = 0 TO 319
  LINE (x, 0)-(x, 199), x AND 255
NEXT

FOR x = 0 TO 304

  'Wait for vsync
  WAIT &H3DA, 8, 8
  WAIT &H3DA, 8

  'restore old background
  IF x > 0 THEN PUT (x - 1, 92), SaveBackground(0), PSET

  'save new background
  GET (x, 92)-(x + 15, 107), SaveBackground(0)

  'Put sprite while preserving background
  PUT (x, 92), SpriteMask(0), OR
  PUT (x, 92), SpriteImage(0), AND

NEXT

For something simple, this works fine. But if you're making a more complicated game, then you'd probably be better off with a library because the sprite routines will be faster and you can eliminate flicker with a double buffer.

(Well if you were a pure qb nut you could use SetVideoSeg, but let's not cross bridges before we get there...)
I really don't get why people say qbs way is simpler. When i was a n00b i remember using qbs get and put then flibs which works the same way. I thought having to create an array first, getting the size right, then using get put with top left corner to bottom right corner was complicated. And not to mention that it really sucked when i had lots of tiles which could vary in size and in count. There simply was no good way to keep it simple in the old fashion way.

I always wanted something that you could allocate with a special routine so that i could store handles to all the sprites and tiles in one small array.

Now which is simpler? This one?

Code:
dim spritea(16*16\2+2) as integer
dim spriteb(16*16\2+2) as integer
dim spritec(16*16\2+2) as integer
dim sprited(16*16\2+2) as integer

get (0, 0)-(15, 15), spritea
get (16, 0)-(31, 15), spritea
get (32, 0)-(47, 15), spritea
get (48, 0)-(63, 15), spritea

Or this one

Code:
dim hSprite(3) as long

uglNewMult hSprite(), 4, UGL.MEM, 15, 15

for  i = 0 to 3
    uglGet hSprite(i), i*16, 0, hVideoDC
next i

I find the second on simple, but maybe it's just me.
even with ugl, you can't automatically load in variable-size images from a bmp. Fortunately I was able to come up with a good and fast method to do so (in ugl). Smile
just because no one else if explaining it...

masks are basically sort of a shadow of the game sprite. it is a copy of the sprite (your spaceship) except it's completely black: 0. the rest is white. sorta when you look at something that's in front of the sun. it appears black and everything else appears white. you put the mask first using xor and then the sprite using pset

put (x,y), mask, xor
put (x,y), sprite, pset

later i'll make a quick example for ya. oh yeah, to get rid of flicker, use this right after the put's.

wait &h3da, 8
Quote:even with ugl, you can't automatically load in variable-size images from a bmp. Fortunately I was able to come up with a good and fast method to do so (in ugl). Smile

Explain... I might be interested...
Quote:just because no one else if explaining it...

masks are basically sort of a shadow of the game sprite. it is a copy of the sprite (your spaceship) except it's completely black: 0. the rest is white. sorta when you look at something that's in front of the sun. it appears black and everything else appears white. you put the mask first using xor and then the sprite using pset

put (x,y), mask, xor
put (x,y), sprite, pset

later i'll make a quick example for ya. oh yeah, to get rid of flicker, use this right after the put's.

wait &h3da, 8

dammit! why didn't i ever think of that!
i've been using 0 and color 255 on the standard palette this whole time. since they're both purest black, i used put with OR and AND to superimpose them. that xor idea is a lot better...
Pages: 1 2