Transparent color
Transparent color
Hello everyone,
I am using Screen 13 and DATA for my graphics. I am trying to make the black transparent so you can't see it. Here's is a example,
data: 000, 150, 150, 150, 000
data: 000, 150, 150, 150, 000
data: 150, 150, 150, 150, 150
data: 000, 150, 150, 150, 000
Is there a way I can get the 000 to not be seen?
Thanks
I am using Screen 13 and DATA for my graphics. I am trying to make the black transparent so you can't see it. Here's is a example,
data: 000, 150, 150, 150, 000
data: 000, 150, 150, 150, 000
data: 150, 150, 150, 150, 150
data: 000, 150, 150, 150, 000
Is there a way I can get the 000 to not be seen?
Thanks
Yes, several ways actually:
1) Dont draw it (aka: Use your own routines instead of the built in ones)
2) Use a mask bitmap
3) Use FreeBASIC (www.FreeBASIC.net)
I dont have time to make up examples..
Maybe someone else will clarify it..
Sorry for the useless post
1) Dont draw it (aka: Use your own routines instead of the built in ones)
2) Use a mask bitmap
3) Use FreeBASIC (www.FreeBASIC.net)
I dont have time to make up examples..
Maybe someone else will clarify it..
Sorry for the useless post
I have left this dump.
- The Awakened
- Veteran
- Posts: 144
- Joined: Sun Aug 07, 2005 1:51 am
Well, I assume you're using the following routine:
Put this instead of the pset
That way, if the pixel is 0, the routine will just skip over it. As for PUTing, you'll have to set up a mask... check out Apester's tutorial, that's where I first got my tips. It's right here: http://petesqbsite.com/sections/tutoria ... s.shtml#11
Good luck to you!
Code: Select all
for y = 0 to yourwidth
for x = 0 to yourheight
read pixel%
pset x, y, pixel%
next
next
Code: Select all
if pixel% > 0 then
pset x, y, pixel
end if
Good luck to you!
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."
A quick explanation o' masks... You can think of masks as holes you put down on an image that allow your sprite to fill them without messing up the background pixels or your sprites pixels. To make a mask you need to make a black cutout of your sprite and slap it on a box of white pixels that are the same size as your sprite, e.g.
The sprite 6x6 for simplicity in:
0,0,0,4,0,0
0,1,1,6,1,1
0,1,0,4,0,0
2,3,2,5,2,2
0,1,0,4,0,0
0,1,0,4,0,0
(note: the transparent pixels MUST be black!)
The Mask - F's for white(QB's color 15):
F,F,F,0,F,F
F,0,0,0,0,0
F,0,F,0,F,F
0,0,0,0,0,0
F,0,F,0,F,F
F,0,F,0,F,F
A quick way to make a mask is to scan over your sprite
and set the masks pixels to White if the color is 0 or
black if it equals anything else
The next step is to PUT(preferrable) the mask down using the AND
operrator, then PUT down the sprite with the OR operrator:
PUT (10, 10), yourmask%(0), AND
PUT (10, 10), yoursprite%(0), OR
and TADA!!!!! You have a sprite with a transparent background!
One problem with masks though, as opposed to a custom
"Dont draw the black pixels" routine. Masks take up twice as much
space cause you need to store the sprite and the mask.
Hope this helps!
The sprite 6x6 for simplicity in:
0,0,0,4,0,0
0,1,1,6,1,1
0,1,0,4,0,0
2,3,2,5,2,2
0,1,0,4,0,0
0,1,0,4,0,0
(note: the transparent pixels MUST be black!)
The Mask - F's for white(QB's color 15):
F,F,F,0,F,F
F,0,0,0,0,0
F,0,F,0,F,F
0,0,0,0,0,0
F,0,F,0,F,F
F,0,F,0,F,F
A quick way to make a mask is to scan over your sprite
and set the masks pixels to White if the color is 0 or
black if it equals anything else
Code: Select all
FOR x% = 0 TO 15
FOR y% = 0 TO 15
col% = sprite(x% ,y%)
IF col% = 0 THEN
col% = 15
ELSE
col% = 0
END IF
mask(x%, y%) = col%
NEXT y%
NEXT x%
operrator, then PUT down the sprite with the OR operrator:
PUT (10, 10), yourmask%(0), AND
PUT (10, 10), yoursprite%(0), OR
and TADA!!!!! You have a sprite with a transparent background!
One problem with masks though, as opposed to a custom
"Dont draw the black pixels" routine. Masks take up twice as much
space cause you need to store the sprite and the mask.
Hope this helps!
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
C:\DOS\RUN
RUN\DOS\RUN
-
- Veteran
- Posts: 1055
- Joined: Sun Jan 02, 2005 2:11 pm
- Location: At my computer
- Contact:
OOPS
WHAT? I thought I posted in the Help forum...sorry, lol.
Thanks everyone, I will try some of your ideas.
Thanks everyone, I will try some of your ideas.
- The Walrus
- Veteran
- Posts: 87
- Joined: Fri Apr 01, 2005 7:19 am
- Location: Denmark
- Contact:
There's also a tutorial on putting transperant sprites here:
http://www.qbasicnews.com/tutorials.php ... =view&id=7
http://www.qbasicnews.com/tutorials.php ... =view&id=7
If swimming is so good for your figure, how do you explain walruses?
Thanks
I used the mask and it worked.
Thanks everyone.
Thanks everyone.
-
- Veteran
- Posts: 1055
- Joined: Sun Jan 02, 2005 2:11 pm
- Location: At my computer
- Contact:
It's all this work that makes FreeBasic Trans option look so nice:
Code: Select all
PUT (x, y), sprite, trans
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
(x.t.r.GRAPHICS)
Wait my bad, I forgot to say why the whole AND and OR thing work...
Okay so you know that a mask's background pixels are white and there is a big black spot in the middle which is your sprite. When you AND on your mask here is what happens:
the masks pixels which are white are in binary as:
11111111
the pixels under the white(the background colored pixels) are in
binary as... we'll say the qb color light red(12):
00001100
now ANDing them together ANDs each bit with the other corresponding bit in the other binary number:
11111111
AND
00001100
======
00001100
Exactly the second number(or the pixels your are ANDing the white on to)! So thats why the white pixels dont get drawn.
Now as for the black (qb color 0):
00000000
AND
00001100
======
00000000
You get 0. Thats why the black pixels show up. But the actual sprite gets ORd on so you're ORing the black and ORing the actual color:
00000000 <-- sprites transparent black
OR
00001010 <-- backgrounds green
======
00001010
You get the background color. And finally for the sprites solid pixels:
00000111 <-- sprites color grey
OR
00000000 <-- cutouts black (made when ANDing the mask)
======
00000111
So all in all, this fancy mix of opperrators creates a transparent sprite!
Okay so you know that a mask's background pixels are white and there is a big black spot in the middle which is your sprite. When you AND on your mask here is what happens:
the masks pixels which are white are in binary as:
11111111
the pixels under the white(the background colored pixels) are in
binary as... we'll say the qb color light red(12):
00001100
now ANDing them together ANDs each bit with the other corresponding bit in the other binary number:
11111111
AND
00001100
======
00001100
Exactly the second number(or the pixels your are ANDing the white on to)! So thats why the white pixels dont get drawn.
Now as for the black (qb color 0):
00000000
AND
00001100
======
00000000
You get 0. Thats why the black pixels show up. But the actual sprite gets ORd on so you're ORing the black and ORing the actual color:
00000000 <-- sprites transparent black
OR
00001010 <-- backgrounds green
======
00001010
You get the background color. And finally for the sprites solid pixels:
00000111 <-- sprites color grey
OR
00000000 <-- cutouts black (made when ANDing the mask)
======
00000111
So all in all, this fancy mix of opperrators creates a transparent sprite!
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
C:\DOS\RUN
RUN\DOS\RUN
- romassoldier
- Newbie
- Posts: 4
- Joined: Tue Aug 30, 2005 9:03 am
HI! My problem isn't in the DATA transparent colors. I use 8 bits .BMPs, and I wanna put the image onto the screen, but the background won't be visible.
I make a BMP file, which is the mask(I saw it in the Sonix game), and the background is 50% grey.
(rehosted, this isn't the original!)
And I open this bmps, and GET dr1, and dr1mask.
BUT if I use this code
Then i don't give what i want. (Transparent backgound...)
I make a BMP file, which is the mask(I saw it in the Sonix game), and the background is 50% grey.
(rehosted, this isn't the original!)
And I open this bmps, and GET dr1, and dr1mask.
BUT if I use this code
Code: Select all
PUT dr1 (1, 1), AND
PUT dr1mask (1, 1), OR
Last edited by romassoldier on Sat Mar 10, 2007 3:17 pm, edited 3 times in total.
Okey pokey, now take a look at the pic on the left. That background cant be pink if your doing a mask, the background needs to be black(QB color 0). Now for the pic on the right, that grey background needs to be white(QB color 15) and all the main pixels, the colored ones that is, need to be black. So you have a sprite with a black background one the left and a white background with a black cutout of your sprite on the right.
An example sprite:
0,1,4,0
1,0,0,4
4,0,0,1
0,4,1,0
That sprites mask:
15,0,0,15
0,15,15,0
0,15,15,0
15,0,0,15
If I could post pics I would. Read my posts again till you get the
hang of it and good luck!(Nice job on those sprites!)
An example sprite:
0,1,4,0
1,0,0,4
4,0,0,1
0,4,1,0
That sprites mask:
15,0,0,15
0,15,15,0
0,15,15,0
15,0,0,15
If I could post pics I would. Read my posts again till you get the
hang of it and good luck!(Nice job on those sprites!)
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
C:\DOS\RUN
RUN\DOS\RUN
- romassoldier
- Newbie
- Posts: 4
- Joined: Tue Aug 30, 2005 9:03 am
ok I will try it, and thanks.
Last edited by romassoldier on Sat Mar 10, 2007 3:18 pm, edited 1 time in total.
I came, I saw, and I didn't believe my eyes...