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 / Adding sprite transparancy

Author
Message
gameangel147
11
Years of Service
User Offline
Joined: 2nd Dec 2012
Location:
Posted: 5th Dec 2012 01:34
I have a sprite with a white background and am trying to make it transparent. I have edited the picture to be transparent but when I save it as a bitmap it just adds white as a background. I currently am just using the standard black background and have tried to change the background using the INK command but have had no luck.
I have also tried using the SET SPRITE command but it has done nothing, so any help here would be appreciated.

This is what I have so far:

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Dec 2012 18:25
Bitmaps don't support the alpha channel. Try exporting it to a .png or .tga.

TheComet

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 6th Dec 2012 01:00 Edited at: 6th Dec 2012 01:00
It helps if the colour key you are looking to hide is at all four corners [Well only one is needed I just cannot remember which... ]

But yeah try other formats too as TheComet has suggested

Ramon156
13
Years of Service
User Offline
Joined: 13th Jul 2011
Location: Netherlands
Posted: 11th Dec 2012 17:14
Everything that's colored black in a sprite, in your source BMP will be hidden in DBPro. That is atleast happening in my program!

I made a 640x480 .BMP level, the black parts count as a collision also, does transparency make it so the transparent parts do not count as a sprite collision?
Just wondering.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Dec 2012 17:33
Quote: "Everything that's colored black in a sprite, in your source BMP will be hidden in DBPro. That is atleast happening in my program!"

That's the default action. You can change which color is treated as transparent, or turn it off completely. But using PNG's with embedded alphas values will also be used automatically and I would recommend using PNG over BMP anyway.

"You're not going crazy. You're going sane in a crazy world!" ~Tick
gameangel147
11
Years of Service
User Offline
Joined: 2nd Dec 2012
Location:
Posted: 13th Dec 2012 07:26
Once I switched to png. I was able to use alpha in the images. I had tried to use the Sprite Hit command for pixel-perfect collision, like I read in a textbook, but it looks like it doesn't work that way.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 14th Dec 2012 02:02 Edited at: 14th Dec 2012 02:03
There's gotta be a snippet somewhere in the forum on pixel perfect collision; have a search.

One method that springs to my mind is to read the transparent pixels and use a hidden sprite to test for collision at the transparent pixels. Based on required precision, the hidden sprite would be 1 or 2 or 3 or more pixels squared. There are plugins that can read pixels, or you can use memblocks.



gameangel147
11
Years of Service
User Offline
Joined: 2nd Dec 2012
Location:
Posted: 14th Dec 2012 22:33
Thanks for the tip Chris, but I'm still new and barely understood any of that, so I will keep it in mind for later but right now I will stick with bounding box collision.

I do have a question though, as I am trying to use tiles and paste them but I have no idea as to how to use data statements to do this. I have an image ready but am stuck there. Any help would be appreciated, though maybe I should make a new thread.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 14th Dec 2012 23:09 Edited at: 15th Dec 2012 14:53
I understand, just so you know that it is possible.

If you want to use data statements for levels then do something similar to this; here we have two data statements at a label called Level.


Level:
Data 0,0,0,0,0,0,0,0,0,0
Data 1,1,1,0,0,1,1,0,0,0


Each zero represents an empty space, and the ones represent a platform.

Establish your own numbering or string system to designate to each type of tile. Create a 2D array to store your tiles. Global Dim Tile(100,20).

Now, when you need to load your level; use the the restore and read commands


Restore Level
Read Tile(1,2), Tile(2,2), Tile(3,2), Tile(4,2)... etc
Read Tile(1,1), Tile(2,1), Tile(3,1), Tile(4,1)... etc


Now your array contains the types of tiles; all you have to do is loop through the level and paste the tiles using sprite frames or images like so:

For x = 1 to 100
For y = 1 to 20
Set Sprite Frame TilerId, Tile(x,y)
Paste Sprite TilerId, x * TileSize, y * TileSize
Next y
Next x

But this is based on your suggestion to use data statements, it can work with data files and other formats.

TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 15th Dec 2012 10:59
Sorry, but I just have to throw out a quick correction Crhis. You don't need the "return" command for data statemetns:



This is sufficient:



TheComet

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Dec 2012 14:25
Thanks

gameangel147
11
Years of Service
User Offline
Joined: 2nd Dec 2012
Location:
Posted: 19th Dec 2012 11:41
Okay so I have questions, as I am trying to wrap my head around this to make sure I understand how it all works.

So you start with data statments to represent tile layouts, then you create an array to store all of the data, in this case a two-dimensional array. Then you call the data and read it into the array.

I am guessing that when "Read Tile(1, 2)" is said, it is telling the program to read the first piece of data and store it in the array location that is 1 across and 2 down.

One question I have on the "for" loops is: does it loop through y and then go to x when y = 20? It seems like it would do 20 loops for y for every x, so would that be 2000 loops (20 * 100)? Also I can't find any commands regarding sprite frames and that is something I am also unfamiliar with.

Again thanks for all of your guy's help with this, I really appreciate it.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 19th Dec 2012 15:03
Quote: "does it loop through y and then go to x when y = 20?"


The for loop counts;
x=1,y=1
x=1,y=2
x=1,y=3
...
x=1,y=20

Then the Y loop expires at 20; then a new X loops starts and repeats a new inner Y loop;
x=2,y=1
x=2,y=2
x=2,y=3
...
x=2,y=20

This is the pattern of a the 2D loop; it could work the other way round
. Think of it as a printer which outputs one row of text, then at the end of the line, it prints a new row of text; only in my previous code, it works from bottom to top, then starts a new column. So the total tiles are indeed 20 * 100.

Quote: "Also I can't find any commands regarding sprite frames and that is something I am also unfamiliar with."


The easiest way to find sprite commands is to write the word sprite in your code editor; then with the caret situated on the word, press F1. This will bring up the sprite command help file, at the bottom of this page you can click the 'SPRITE Commands Menu' link, which will show you all the commands you can do with sprites; which are simply entities that facilitate animation and interactive commands and applies them to images on the viewport.

There are other ways to create levels with images or sprites; just investigate and pick what you are most comfortable with.

gameangel147
11
Years of Service
User Offline
Joined: 2nd Dec 2012
Location:
Posted: 19th Dec 2012 22:13
Thanks for clearing that up, it makes more sense now. And I know about the commands menu but for some reason I couldn't find that command until now.

I am just confused as to where you link the data to a specific tile. You have the data in the array, but how does the program know that a 1 means "Tile1.png", and 0 means nothing and a 2 means "Tile2.png" and so on?
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 20th Dec 2012 17:22
How does DBPRO refer to loaded images and sprites?

Through numbers. Therefore, each tile's numeric identity, within the array, refers to the image number, sprite number or sprite frame, depending on how you want to work. In my example I just used sprite frames, which would be initiated using the Create Animated Sprite command.

If your images are loaded as individual files (tile1.png, tile2.png and so on), you'd omit the sprite frame commands and simply paste the image number at the designated location. Here is a hassle free way to load all of your tiles automatically; not secure, but will do for development phase.


You should also assign the image to a class. This class would store your properties for each tile type, such as whether the tile is solid for collision, breakable, whether the tile causes damage, whether the tile is a spawn point for the player or entity. Classes in DBPRO as you know are created using user defined types; and each instance would share an array index; and that array index is the identical number of your tile image (If you want it to be).

So to paste the image of tile type 2; Paste Image 2, x, y.

To check if tile type 2 blocks movement; If TileClass(2).Solid = 1

To check if tile type 2 causes damage; If TileClass(2).Damage > 0

And so on

Login to post a reply

Server time is: 2024-11-23 18:13:38
Your offset time is: 2024-11-23 18:13:38