Masks (please explain the methodology)

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Agent_Firestalker
Coder
Posts: 18
Joined: Fri Feb 11, 2005 11:51 am
Location: Lea Monde Ruins

Masks (please explain the methodology)

Post by Agent_Firestalker »

I've read more tutorials on masking than..... (shouts at wall)
Anyway, lets say I want to draw, um, a simple 10x10 sprite. And the sprite is composed of a perfectly center 5x5 square, in red. Now the mask would have the area around the 5x5 sq. black, with the 5 x5 sq. in white, right.

I'm trying to figure out how you take a predrawn graphic (in my case, a 15x15 charatcer sprite, and get it's mask, in as short a version as possible. Oh, and since i'm trying to figure this out, give a comment or too. 'okay

Thanks,
Agent_Firestalker
"I ask you, is this a job for intelligent men?"
"Well show me one, i'll ask him?"

Val and Earl - "Tremors"
indeed005

masking, old style

Post by indeed005 »

Before i start, can i just suggest that u try using a library
like Future Library by jorden chamid, availalbe from this site.
It still requires you to use a separate background for each sprite,
but don't need to mask them, you just set the colour you want it to ignore.

first, GET the image on a black background into an array
then, clear it, with a filled box of colour, say, 255, and then
GET it again into a different array. This is going on memory...
then, when putting the sprite, PUT the first array with an AND
and the second directly over the top with an OR. u dig?
beanay88@hotmail.com. if u want help, make the subject 'sprite help'
or something
oh, then you'lll have to have a third array for th background.

here's how it should go, shorthand

DIM 3 separate arrays
DRAW sprite
GET sprite into array1
CLEAR with a color
DRAW same sprite again
GET into second array
draw the level
GET the background
start the game loop
PUT the background
MOVE the sprite(but not draw)
GET the background
PUT array1, AND
PUT array2 OR
---> loop again

i think that's right

:D
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

FreeBasic has a transparent PUT that would save you a lot of work. No need of masking....
Dapper D

Post by Dapper D »

Ok, if you wanna do it the good ol' fashioned way, do this:

DIM sprite(10,10)
FOR y = 1 to 10
FOR x = 1 to 10
READ whatever
IF whatever = 0 THEN PSET (x,y), 0
IF whatever = 0 THEN PSET (x,y),4
NEXT:NEXT

DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

GET (1,1)-(10,10),sprite

And the mask is as simple as this...

DIM spritemask(10,10)
FOR y = 1 to 10
FOR x = 1 to 10
READ whatever
IF whatever = 0 THEN PSET (x,y), 255 ' YOU USE 255 TO MASK COLORS
IF whatever = 0 THEN PSET (x,y),4
NEXT:NEXT

DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

GET (1,1)-(10,10), spritemask

It's as simple as that. Well, if you wanna do it the slow old fashioned way.
Guest

Post by Guest »

Okay, Ignore what I just posted... i made an error.

Here ya go:

DIM sprite(10,10)
FOR y = 1 to 10
FOR x = 1 to 10
READ whatever
IF whatever = 0 THEN PSET (x,y), 0
IF whatever = 1 THEN PSET (x,y), 4
NEXT:NEXT

DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

GET (1,1)-(10,10),sprite

And the mask is as simple as this...

DIM spritemask(10,10)
FOR y = 1 to 10
FOR x = 1 to 10
READ whatever
IF whatever = 0 THEN PSET (x,y), 255 ' YOU USE 255 TO MASK COLORS
IF whatever = 1 THEN PSET (x,y), 4
NEXT:NEXT

DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,1,1,1,1,1,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

GET (1,1)-(10,10), spritemask

It's as simple as that. Well, if you wanna do it the slow old fashioned way.
Post Reply