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.

2D All the way! / Displaying background through sprite

Author
Message
Devonps
14
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 7th Jul 2010 00:07
I'm creating a 2D roguelike using tiles/sprites and have created some place holder images, which I'm using them to represent the dungeon walls, floors & objects. I'm also using a SPRITE to display the player character.

I've created all objects using The GIMP with a black background.

My problem is that the floor of the dungeon is not visible when the player character (or object) is at the same location.

I would like both the dungeon floor and PC to be visible at the same time, i.e. you can see the dungeon floor behind the player character.

Loading of the images looks like


The dungeon drawing routine essentially looks like


Hopefully this is a simple answer...!?


Steve.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 7th Jul 2010 23:06 Edited at: 11th Aug 2010 22:15
It might be an alpha channel problem. When DbPRO loads a PNG, it uses the Alpha channel from the image, ignoring the colour key. You could try saving your images in some other format (such as BMP) and see if that solves the issue.

also, the expression in your second snippet appears to be malformed. If you want to make a single line comparisons, use the IF/THEN pairing. If you're after multi line, then IF/ENDIF. Who knows how Dbpro will see the expression otherwise.


So this,




Could be,



or,



Devonps
14
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 8th Jul 2010 10:36
Hi Kevin,

Thanks for the response, in reverse order...

That was a cut/paste error on my part - doh!

I took one of my images and saved it as a .bmp file and still I got the same issue, I've attached a screen shot showing my issue.

I might try and use an existing RPG tileset and see if I get the same issue.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!

Attachments

Login to view attachments
Devonps
14
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 8th Jul 2010 10:38
Hi Kevin,

Thanks for the response, in reverse order...

That was a cut/paste error on my part - doh!

I took one of my images and saved it as a .bmp file and still I got the same issue, I've attached a screen shot showing my issue.

I might try and use an existing RPG tileset and see if I get the same issue.

edited: spelling mistake.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
nackidno
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Där solen aldrig skiner
Posted: 8th Jul 2010 12:48
Here:



Shouldn't it look like?:



It was a loooong time since I used DBPro though, so I might be mistaken.

David Gervais
Retired Moderator
18
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 8th Jul 2010 13:49
The first code sample is what is shown in the help file.. color zero ( aka r0,g0,b0) is the default color transparency. try just to 'rem' out the colorkey line. see if the default kicks in..

Just a thought.

Cheers!

Devonps
14
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 8th Jul 2010 14:57
@David tried that and the effect is still the same, BTW I copied some of your old tilesets across and I'm still getting the same issue.

I've also copied over some of your old RPG tilesets and still get the same issue.

FYI: For all dungeon objects, except the player, I use the PASTE IMAGE command; For the player I use the SPRITE command.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
David Gervais
Retired Moderator
18
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 8th Jul 2010 18:43
hmmm, while I was working with IBOL on the GotG upgrade he had a wierd bug too.. the player sprite was not showing as transparent,.. then he realized that he was not drawing the floor under the player, so it looked like the tile the player was on was black background instead of the ground.. he fixed it, and I also made an adjustment of stamping the player sprite on a floor tile.. this seemed to work.. I'll need to go try making the player and stuff alpha channel .png again and see if the floor tiles show up properly now..

I know that the alpha channel .png works, but I never played with the set color key.. it might only work for the 'paste image' and not the sprite commands, since the help on 'set color key' is in the image commands section.

You need to do some basic tests first.. get it to work alone, then it should work as intended, we just need to wrap our heads around what is "as intended".

Cheers!

nackidno
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Där solen aldrig skiner
Posted: 8th Jul 2010 19:01


Alright! I don't have DBPro installed so I couldn't check. ^^

Devonps
14
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 8th Jul 2010 19:45 Edited at: 8th Jul 2010 19:51
Quote: "You need to do some basic tests first.. get it to work alone"


Not quite sure what you mean but I took the player drawing part out of my dungeon draw loop - as I too was placing the player as I came across him during the dungeon draw loop - and placed it after the loop has finished.

Even after I've drawn the dungeon and then placed the player I still get the same result, i.e. a black background. I've tried with the following commands: Sprite, Paste Sprite and Paste Image and with the Set Image ColorKey command active/non-active.

I'll quickly redraw a new player sprite (.png) and test that. That didn't work either!

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
David Gervais
Retired Moderator
18
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 8th Jul 2010 21:41 Edited at: 8th Jul 2010 21:42
Ok, I'm trying to figure this out,.. take this code snippet..



and these 2 images..

ping with alpha channel..


bitmap (bmp) with black for transparency..



this sets the image colorkey (before the bmp is loaded as per the example in the help file)

A sprite of image 1 (bmp) is placed at the mousex() mousey() position and offset to the right and down 64 pixels is the sprite of image 2 (alpha png)

they look fine to me and have the transparency shown correctly..

press the left mouse button mouseclick()=1 and I do a 'paste image 1' (bmp) and a 'paste sprite 1'(bmp) in upper right side of screen. Notice that the 'paste image' does not show the black as transparent but the 'paste sprite' does. (so apparently the 'paste image' using the bmp does not take the color key into account.)

press the right mouse button mouseclick()=2 and I do a 'paste image 2' (alpha png) and a 'paste sprite 2' (Alpha png) in lower right side of screen. Notice that the 'paste image' does not show the black as transparent but the 'paste sprite' does. (so apparently the 'paste image' using the Alpha png does not take the alpha channel info into account.)

My Conclusion, 'Paste Image' is not working as intended.

What might be the solution? use 'Paste Sprite' instead?

This is about all I can do to help. Sorry if it only serves to confuse the issue.

Cheers!

Devonps
14
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 9th Jul 2010 09:57
Thanks for the demonstration code, I'm going to try the solution you offer of using paste sprite for all my objects.

I have one question for you what program are you using to generate your images?

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
Devonps
14
Years of Service
User Offline
Joined: 5th Nov 2009
Location: Nottingham
Posted: 9th Jul 2010 10:28 Edited at: 9th Jul 2010 10:29
I've solved it - thanks in no small part to David's demonstration and commentary

My issues were:
1. I incorrectly created my .PNG files with a black background rather than a transparent background.
2. My player placement routine updated my dungeon map with the coordinates of the player - thus overwriting anything that was stored at that location.

I resolved the above by...

1. Recreating a .PNG file with true transparency
2. Removing the offending code from the player placement routine (but still storing the location of the player)
3. Removed a logic check for the players location to outside of the dungeon drawing routine.
4. Used PASTE SPRITE for my player

This all now works as expected! I'm just glad I caught it now before I'd put more images into my game.

Marriage is a circle of rings....
Engagement ring, Wedding ring, Suffering!
David Gervais
Retired Moderator
18
Years of Service
User Offline
Joined: 28th Sep 2005
Location: Montreal, Canada
Posted: 9th Jul 2010 13:10
Devonps, I use PSP7 and Artgem. (Artgem is no longer available, but you can do what you need even with the demo version that can still be found around the net. v1.3 is the latest version that I know of.)

Other free programs like Gimp also work well for this.

Cheers!

Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 11th Jul 2010 13:40 Edited at: 11th Jul 2010 13:41
Quote: "My Conclusion, 'Paste Image' is not working as intended."


Hi!

The color key is used when loading an image. While Direct3D loads the image, it instantly converts the color key to transparency.
Paste image disables the alpha channel by default. You have to add an extra parameter "paste image nr,x,y,1" to enable the alpha channel.

Cheers!
Sven B

Login to post a reply

Server time is: 2024-04-24 16:53:22
Your offset time is: 2024-04-24 16:53:22