Problem with PNG with alpha channel

Find quick help here to get you started with Hollywood
Post Reply
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

Problem with PNG with alpha channel

Post by ocean77 »

Do I need to do anything special to be able to display a layer with a png brush containing transparent areas properly?
The computer on the desk is supposed to light up when the mouse pointer is over it. Which it does, but the area around
it is also affected. I've simply used a curves modifier in gimp to the relevant portion on the image and isolated it from the background. But almost looks as if the alpha layer is carrying that information with it even though I cut out the area around it.

This is what I get:

https://drive.google.com/file/d/1sW1CZj ... sp=sharing

And this is a screengrab (in order to show the transparent area properly) of the png I am trying to display:

https://drive.google.com/file/d/1rYGfdp ... sp=sharing

What's going on here?
PEB
Posts: 567
Joined: Sun Feb 21, 2010 1:28 am

Re: Problem with PNG with alpha channel

Post by PEB »

Maybe you're not loading the alpha-channel in your Hollywood script; or maybe you're not saving it correctly in GIMP.

If you upload the image with the transparency to Google Drive and paste some lines from your script (the code that you are using to load and display that image), then I (or someone else here) should be able to figure out what's going wrong.
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

Re: Problem with PNG with alpha channel

Post by ocean77 »

Okay, thanks.

Here's the image:
https://drive.google.com/file/d/18twPcx ... sp=sharing

This is the relevant code:

Code: Select all

Function p_Stage01()
    
    SetMusicVolume(2, VolMus)

    @BGPIC 2, "Stage01.jpg"
    @MUSIC 2, "Ambience_01.ogg"
    @BRUSH 1, "terminal_hilight.png"
    DisplayBGPic(2)
    PlayMusic(2, 0)
    
MakeButton(1, #SIMPLEBUTTON, 20, 250, 120, 120, {OnMouseOver = p_Stage01EventFunc, OnMouseDown = p_Stage01EventFunc, OnMouseOut = p_Stage01EventFunc})

/* InstallEventHandler({OnMouseOver, OnMouseOut, OnMouseDown = p_Stage01EventFunc}) -------- Redundant*/

EndFunction

Function p_Stage01EventFunc(msg)
    
    Switch msg.action
    Case "OnMouseOver":
        
        /* DisplayBrush(1, 0, 209, {LoadAlpha = True}) --- Removed */
        
        InsertLayer(1, #BRUSH, 1, 0, 208, TRUE)
        ShowLayer(1)
        
        PlaySample(1, {Volume = VolSnd})
        
    Case "OnMouseOut":
        HideLayer(1)
    
    Case "OnMouseDown":
        PlaySample(2, {Volume = VolSnd})
        StopMusic(2)
        HideLayer(1)
        Stage = 0
        p_MainMenu()
    EndSwitch
    
EndFunction
I didn't notice any options for adding an alpha layer in the documentation when using layers. But I am just learning so I might have missed a whole bunch of things.
User avatar
emeck
Posts: 169
Joined: Fri Apr 03, 2015 3:17 pm

Re: Problem with PNG with alpha channel

Post by emeck »

Hello

Try with

Code: Select all

@BRUSH 1, "terminal_hilight.png", {LoadAlpha = True}
PowerBook 5.2 MorphOS 3.15
PowerBook 5.8 MorphOS 3.15
Amiga 1200 BPPC/BVision AOS4.1 FE
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

Re: Problem with PNG with alpha channel

Post by ocean77 »

emeck wrote: Sat Feb 13, 2021 8:50 am Hello

Try with

Code: Select all

@BRUSH 1, "terminal_hilight.png", {LoadAlpha = True}
Beautiful! Thank you so much! :)
Bugala
Posts: 1168
Joined: Sun Feb 14, 2010 7:11 pm

Re: Problem with PNG with alpha channel

Post by Bugala »

Notice also that if it still fails even after LoadAlpha=true, then problem is likely how you have saved the png. I myself have several times ran into this problem where code works right but I have saved the image file itself wrong way. In Gimpfor example it has this checkbox on pngs that needs to be checked to save that alpha channel info.
Bugala
Posts: 1168
Joined: Sun Feb 14, 2010 7:11 pm

Re: Problem with PNG with alpha channel

Post by Bugala »

And also, you might be able to use SetLayerTransparency() command to do some trick as well.

That to use your current image as an example.

You could make it have double the amount of light it now has.

Then when you show it on OnMouseOver, you could also add SetLayerTransparency(1, 126)

and then when OnMouseDown, you could SetLayerTransparency(1, 0)

this way you could be using same image to have two different highlights. First one would be the OnMouseOver which would be showing the picture with halftransparency, making it look like having half the light.

Then on OnMouseDown you would show the image without any transparency (0) which would look like it is brighter than the previous transparency level.

This way in case you want different amounts of highlight, you can have them without having more than one image.
ocean77
Posts: 111
Joined: Mon Jan 28, 2019 8:34 pm

Re: Problem with PNG with alpha channel

Post by ocean77 »

Bugala wrote: Sat Feb 13, 2021 10:38 am This way in case you want different amounts of highlight, you can have them without having more than one image.
Great tip. Thanks! :)
Post Reply