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 / Sprite Backgrounds.

Author
Message
Zyronagon
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location: USA
Posted: 20th Feb 2010 21:20
How do you make the background of a sprite transparent?
Zyronagon
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location: USA
Posted: 21st Feb 2010 13:51
Let's not all get up and answer at once...

I used set image colorkey 0,255,0. That's the color, I've checked multiple times. Is there something else I have to do?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 21st Feb 2010 15:20
Quote: "Let's not all get up and answer at once..."


Let's not take a quick look in the help files...

SET SPRITE Sprite Number, Backsave, Transparency

..and there's a whole section on sprites in the Command section with examples you can run if the help files don't help.

People on here won't always instantly answer very basic questions if it looks like you haven't at least tried to help yourself first.

TDK

Zyronagon
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location: USA
Posted: 22nd Feb 2010 01:36
Thanks TDK. btw, I did look at the help files and all of the sprite, image, and 2D commands, but I didn't think a command entitled "Set Sprite" would change the transparencey. I searched the forums too, which led me to the failed "Set Image Colorkey" command.

The ironic thing is, about a year or two ago I was using DarkBASIC Pro and made the background transparent. I didn't remember the command, and couldn't find the project file.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 22nd Feb 2010 01:57 Edited at: 22nd Feb 2010 02:00
I don't believe that SET SPRITE is what you are looking for. SET IMAGE COLORKEY will do the trick, provided that you use it in the correct manner.

This code demonstrates:



You MUST use the SET IMAGE COLORKEY command before you get the image. That's how DBPro knows to set up the alpha channel for images grabbed with specific color used for transparency.

By the way, the description of SET IMAGE COLORKEY in the help file explains this quite well.

Zyronagon
16
Years of Service
User Offline
Joined: 6th Mar 2008
Location: USA
Posted: 24th Feb 2010 00:39
I tried it, and it still didn't work.

Then it hit me.

The last time I was using 2D in DBP, I was using .bmp files. This time, however, I was using .PNG files. I converted the files into .bmp images and it works perfectly. And thanks Rich, you're right. It was SET IMAGE COLORKEY, not SET SPRITE.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 24th Feb 2010 03:23
Good job then Zyronagon!

However, you should know that a .png graphic has an alpha channel, so you could use a transparent background on your sprite instead of color keying out the green. If you DO use a png with alpha channel, you can also have semi-transparent pixels, for instance shadows. The png format is really better than bmp for sprites that need transparency.

But if all your sprites already have a green background, then by all means, color key away!

Login to post a reply

Server time is: 2024-11-24 20:44:32
Your offset time is: 2024-11-24 20:44:32