Author Topic: Blitting transparency troubles  (Read 1024 times)

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Blitting transparency troubles
« on: November 23, 2012, 03:59:20 pm »
:D Me again,

I've got a HUD on my game at the moment that uses blitting of bitmap images as textures to put images on the display.

I'm slightly confused as to the behavior I'm seeing though.

The documentation (and just, the way the methods seem to suggest they work) implies that something like this:
Code: [Select]
buffer.blit(btn1,0,0,0,0,32,32,32,32,[b]0[/b],false);would render the image with all areas of 0,0,0 as transparent.

However, it renders all areas with colours values less than 16,16,16 (so 15,15,15; 14,14,14; 13,13,13; etc.) as transparent. D:

Is there a way to stop this? (I've checked what colour depth I've been using, and switched variables around: none of it seems to make any difference.)

The other thing in conjunction with this is that it'd be nice if there was a way to set a particular colour to be used as transparent rather than 0,0,0 -> 16,16,16 - I mean, if I used 255,0,255 (a colour I'm not using) for transparency , then all black values would be available.

I keep looking through the documentation for a method along the lines of:
Code: [Select]
setTransparentColor(int r,int g,int b)or something. :(

Please enlighten me :D! There has to be something I'm doing wrong. xD

Offline KittenKoder

  • int
  • **
  • Posts: 66
  • I Am No One Else
    • View Profile
    • Kitt Games Wiki
Re: Blitting transparency troubles
« Reply #1 on: November 23, 2012, 05:27:35 pm »
The transparency key values have a variance due to JPEG inaccuracies, try using pngs if you want perfect. ;)
When life throws you lemons, make lemon juice, then drop life into a pile of razors and pour the lemon juice over it.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Blitting transparency troubles
« Reply #2 on: November 23, 2012, 06:08:24 pm »
Yes, that's the engine's default way to compensate for compression artifacts. If you need more control, create an image with an alpha channel, save it as PNG and load it via the constructors that have the useAlpha attribute.

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: Blitting transparency troubles
« Reply #3 on: November 23, 2012, 08:27:16 pm »
Ah yes!

I knew I was being a retard xD

I had them saved as .png images already, I just wasn't loading with the transparency flag turned on.

Now everything works nice and awesomely. :D

Offline KittenKoder

  • int
  • **
  • Posts: 66
  • I Am No One Else
    • View Profile
    • Kitt Games Wiki
Re: Blitting transparency troubles
« Reply #4 on: November 23, 2012, 10:10:51 pm »
Ah yes!

I knew I was being a retard xD

I had them saved as .png images already, I just wasn't loading with the transparency flag turned on.

Now everything works nice and awesomely. :D

Not retarded, you just made a typo from the sound of it. Typos happen, it's the reason we test things. Yes, PNG is a great format for images, in spite of it being a slightly larger file, you can make per pixel translucency, a wonderful format.
When life throws you lemons, make lemon juice, then drop life into a pile of razors and pour the lemon juice over it.