Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Transparent Pixels in Sprites

Author
Message
Tom_Nally
18
Years of Service
User Offline
Joined: 27th Jul 2006
Location:
Posted: 27th Jul 2006 08:18
I have a question or two about DarkBASIC sprites.

In a bitmap loaded for the purpose of creating a sprite, how does the DarkBASIC engine know which color pixel is supposed to be transparent?

Also, suppose, for example, white happens to be the pixel color that the engine renders as transparent. Suppose further that we use white pixels in another region of the sprite, but that we want those particular white pixels to be NON-transparent. How do we make the engine understand that some white pixels are transparent, while other white pixels are non-transparent?

Thanks.

---Tom Nally, New Orleans
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Jul 2006 11:38
Use PNG images with transparency (the alpha channel). Then you can use the full range of colours and have transparency



Tom_Nally
18
Years of Service
User Offline
Joined: 27th Jul 2006
Location:
Posted: 27th Jul 2006 17:36
Quote: " Use PNG images with transparency (the alpha channel). Then you can use the full range of colours and have transparency."


I think that the effect that you are referring to is what I call "translucency", wherein an image is sort of "ghosted" on top of background images.

What I'm referring to is simply the pixels that are part of the full rectangular image, but don't appear when the image is drawn to screen.

For instance, say that I wanted to make a sprite ball that was 60 pixels in diameter. I would need to produce it with a rectangular bitmap file (or some such...I probably wouldn't use png...at least not initially) that was 60 pixels by 60 pixels. Those pixels in the 60x60 image that are not part of the ball are the ones that I would refer to as "transparent".

I think I may have found a partial answer, at least. In the book by Harbour, I think he's saying that the transparent pixels need to be set to (0,0,0), or black.

I'll presume that's the case. If so, suppose I want to use black elsewhere in the sprite, but want it to render as BLACK, rather than as a transparent pixel.

What should I do? Should I give those pixels a color that are "near" black, such as (1,1,1)?

Thanks!

---Tom Nally, New Orleans
Captain America
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Here
Posted: 28th Jul 2006 07:59
DarkBASIC always renders pure black as transparent, so if you want something to be black but not transparent then yes! you would make it almost pure black.

Plus you can use the set sprite command to set the transparency, and you can say 'paste image image_number,x-coords,y-coords.1'
to set pure black to transparent on images.


Cheers,
Capt. America
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Jul 2006 10:01
Quote: "Should I give those pixels a color that are "near" black, such as (1,1,1)?"


Yes, but I believe at least one of the channels must be > 10. For example, 1,1,1 would still be transparent.

There is also a command, SET IMAGE COLORKEY (I think, may be slightly out on the syntax) that allows you to pick a colour. So you could set it to pink if you like.



Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 28th Jul 2006 11:35
And as Batvink said, you can use .png etc that have an alpha channel.

Set the alpha channel for the bits of the rectangle you want to disappear all the way to the max, and they will be gone in DBP!

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Ginga
18
Years of Service
User Offline
Joined: 3rd Jul 2006
Location: Dorset, England
Posted: 28th Jul 2006 16:04
Quote: "Set the alpha channel for the bits of the rectangle you want to disappear all the way to the max, and they will be gone in DBP!"


Does that work in the bog standard DBC
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 29th Jul 2006 00:01
No, and this is the reason that we ask you peeps to put whether you are using DBC or DBP in the thread title.

Another wasted minute helping people. {shakes head and wanders away sadly}

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Tom_Nally
18
Years of Service
User Offline
Joined: 27th Jul 2006
Location:
Posted: 29th Jul 2006 08:59
(Platform: DBC)

Gents:

Thanks for your help. I'm probably not going to use a .png format image...at least not initially. It's much more likely that, at my current position at the lower end of the learning curve, I'm going to use the standard bitmap format, and will probably do so with Windows Paint. That's why I keep getting back to the issue regarding the color that the DBC engine will render as transparent in the default settings.

But we've exchanged enough information that I think an experiment is in order! I'm inclined to make a big, rectangular sprite...in standard bitmap format, of course. I could subdivided it into sixteen sub-rectangles, say, with each one a differnet color in "near black". For instance, (1,1,1), (10,10,10), (0,0,10), etc. I would put a red border around each sub-rectangle so that they could be differentiated. Then, I could draw this sprite on top of a patterned background, and move it around under mouse control to see which rectangles render as "transparent".

This is still only a thought, but it would be a good exercise to help me start climbing the learning curve.

Thanks again.

---Tom Nally, New Orleans
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 29th Jul 2006 11:36
4,4,4 is visible Black


0,0,0
1,1,1
2,2,2
3,3,3

Are all transparent in DBC.

Tom_Nally
18
Years of Service
User Offline
Joined: 27th Jul 2006
Location:
Posted: 30th Jul 2006 12:18
(Platform: DBC)

To add to what Pincho said...

Varying the red only in increments of 4, I see that (4,0,0) is transparent, while (8,0,0) is "near black".

Varying the green only in increments of 4, (0,4,0) and (0,8,0) are both rendered as "near black".

Varying the blue only in increments of 4, (0,0,4) is transparent, while (0,0,8) is rendered as "near black".

I have to add that I'm not even sure what video mode I am using. I'm using whatever default video mode DBC uses if the programmer doesn't specify one. I guess that's another variable with which we could experiment.

Thanks for everybody's ongoing help and interest.

---Tom Nally, New Orleans

Login to post a reply

Server time is: 2024-11-26 14:47:08
Your offset time is: 2024-11-26 14:47:08