[SOLVED]Room does not show opacity layer

Started by Racoon, Thu 16/04/2020 18:33:46

Previous topic - Next topic

Racoon

Hey,
so I am trying to have a 60% opacity layer of black as a room object to simulate nighttime. But AGS does not recognize it and just shows nothing. I have had this problem before and could "fix" it, by using the spray tool to create the layer, wich worked to some point, but was a lot of work to try to get to look neat. So it seems like the problem is only with constant opacity? Can someone explain and maybe offer a solution?

Crimson Wizard

Quote from: Racoon on Thu 16/04/2020 18:33:46
Hey,
so I am trying to have a 60% opacity layer of black as a room object to simulate nighttime. But AGS does not recognize it and just shows nothing. I have had this problem before and could "fix" it, by using the spray tool to create the layer, wich worked to some point, but was a lot of work to try to get to look neat. So it seems like the problem is only with constant opacity? Can someone explain and maybe offer a solution?

It should normally work. Can you tell how do you do that exactly?

(although I'd suggest to use a GUI, as it's simplier and may be used in many rooms)

Racoon

Hm, I just make a black layer. Turn opacity to 60% and export as png. Then I added it as a sprite and put it in the room. But it does not work. The only way it works is if I spray it with the spray tool, but even then: It looks nice enough in my paint program, but when I add it as a sprite most of the time it shows white patches still.

I tried to put an 100% opacity object behind it, with the result that the the object is shown with the dark layer above it, but apart from that the dark layer is not visible. Maybe I am doing something wrong, but I dont know what..

Crimson Wizard

Quote from: Racoon on Thu 16/04/2020 18:54:20
Hm, I just make a black layer. Turn opacity to 60% and export as png. Then I added it as a sprite and put it in the room.

Oh, so you are making a png image with 60% alpha value? Have you tried making an opaque black sprite and set object Transparency in AGS?

Regarding the error, when you import sprite, do you have "Keep alpha channel" checkbox on? Is the sprite 32-bit?

(Note, with GUI you dont even need to make sprites, as you may set black background color in the editor.)

ManicMatt

When you imported the sprite, was it set to "leave as is" or use the top left pixel, or something else? It should be imported with "leave as is" otherwise the whole sprite will be considered the background part of the sprite.

I'm guessing it's that, anyways.

And a GUI is going to be more flexible, especially when an object cannot be called in a global script. But it always helps to learn what it is you're doing wrong for future reference regardless of whether you stick to an object or a GUI.

Racoon

Quote from: ManicMatt on Thu 16/04/2020 19:05:45
When you imported the sprite, was it set to "leave as is" or use the top left pixel, or something else? It should be imported with "leave as is" otherwise the whole sprite will be considered the background part of the sprite.

I'm guessing it's that, anyways.

And a GUI is going to be more flexible, especially when an object cannot be called in a global script. But it always helps to learn what it is you're doing wrong for future reference regardless of whether you stick to an object or a GUI.

Ahh, yes that was the problem. Thanks a lot!
Yeah, I am trying to get more flexible, but since I am completly new to coding working with GUI always seems like the more complicated step.

Cassiebsg

Don't be afraid of GUIs, they're your friend.  (nod)

Simple steps:
- Create new GUI
- size it to the game res, so it fills the entire screen
- set it to non-clickable, so it won't be in the way of clicks
- Set the BG color to black and no border
- Set transparency to 60%
- name it: gNight (as an exemple)
- set it to normal and not visible


Now you can just call it in script: gNight.Visible=true;  to make it night and  gNight.Visible=false; to make it back to daytime.  ;)

And if you want something more "fancy" you can make it fade in/out if you like.
There are those who believe that life here began out there...

ManicMatt

Yay! I finally solved someone's conundrum hahaha!

I understand what you mean, I was at first avoiding GUI things but it turned out to not be as difficult as I thought it would be. Good little tutorial by Cassiebsg here!

Slasher

Quote from: ManicMatt on Fri 17/04/2020 08:25:10
Yay! I finally solved someone's conundrum hahaha!

I understand what you mean, I was at first avoiding GUI things but it turned out to not be as difficult as I thought it would be. Good little tutorial by Cassiebsg here!
Easy as eggs on a summers' day ManicMatt  (nod)

ManicMatt


Racoon

Thanks to you as well Cassiebsg& Crimson Wizard! I will try out to make a GUI the next time I want to inlcude something like that.

And I am really greatful, that often my problems are solved within a day everytime I post a question. A lot of nice people around.

Racoon

Hey, so I´ll reuse this thread for some more questions.

I am almost done with my game now (Yay!), and so I have to tackle all things that have been left over till now.

1) I use this
Code: ags
void DisplayText(String text)
{
    lblMessage.Text = text;
    gMessage.Visible = true;
    int time_to_wait = Game.TextReadingSpeed * text.Length;
    WaitMouseKey(time_to_wait);
    gMessage.Visible = false;
}

for my text. Now there are some lines that are too long, that I need to append. I found an example  in the manual,
Code: ags
String mytext = "Hello";
mytext = mytext.Append("World");
Display(mytext);

but I don´t knwo how I would apply it to "DisplayText"".

2) I want the description of a hotspot to change after looking at it. I found this
Code: ags
    if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) ==hotspot[1] && bool==false) // bool is the bool name you gave it and use its hotspot i.d. and even add the players room so it only applies in that room (if global.)
     
    // Describe as this
    else
     // Describe as this
     

posted by Slasher in another thread. But how does "Describe as this" work? Do I make a new Text GUI for it?

3) When I have an item selected in the inventory window I would like to deselect it by right mouse click like it does outside the inventory.

And also is there an easy way to prevent the mouse cursor going to "Look" whenever items are combined?

4) I use this script by Khris to make the Audio play continously
Code: ags
AudioChannel *bgm;
    void SetBGM(AudioClip *music) {
      if (bgm == null || bgm.PlayingClip != music) bgm = music.Play();
    }

and if possible I would like to reduce the volume, when you enter a building. I found this
Code: ags
AudioChannel* chan = aExplosion.Play();
chan.Volume = 20;

but how can I use it without making the clip play again?

If made it through to this, thank you a lot for reading all that stuff!




Matti

#12
1) Isn't this working?
Code: ags
String mytext = "Hello";
mytext = mytext.Append("World");
DisplayText(mytext);


2) You don't need a new gui for this but you'll change the text of the label you already got for the hotspot names. You might want to check out my answer in this thread (there, instead of a variable I check the object's changed graphic).

3) You'll need to check eMouseRightInv in the on_mouse_click function.
Code: ags

if (button == eMouseRightInv)  player.ActiveInventory = null;

Khris

1) Call DisplayText() two times or make the label bigger in the GUI editor.

2) If you mean the short text that appears when you hover the mouse over the hotspot, that's unfortunately not that easy to accomplish. The property is Hotspot.Name, and it's read-only. Slasher was talking about an actual description, i.e. something the player character says about the hotspot.
A common workaround for changing the read-only description is what Matti links to, i.e. directly change the label's text from @OVERHOTSPOT@ to a custom name. This requires repeatedly_execute code in the global script though.

4) you can simply do
Code: ags
  bgm.Volume = 20;

Since you'll probably be doing this from a room script, you need to make the variable global first though.
Directly after  AudioChannel *bgm;  add the line:
Code: ags
export bgm;

In the global header, add
Code: ags
import AudioChannel *bgm;

Racoon

1) Oh man, my label was wider than the game width and I just needed to change that. So that was easy to solve   :-[
2) Okay, I read a bit about what Matti wrote in the other thread and I think I might not be able to do that. I will take the easy solution here and just let the character describe it with DisplayText. Thanks for the idea though!
3)I tried to put Mattis code in mouse_on_click, but it did not change anything.
4)Thank you Khris! That is so easy to use.

Khris

2) Why not? It's not that hard, just annoying to script.

3) To be precise, you need to turn on custom inv click handling in the General settings, and you'll want something like

Code: ags
  // after eMouseRight block
  else if (button == eMouseLeftInv) {
    InventoryItem *ia = inventory[game.inv_activated];
    if (mouse.Mode == eModeInteract && player.ActiveInventory == null) player.ActiveInventory = ia;
    else ia.RunInteraction(mouse.Mode);
  }
  else if (button == eMouseRightInv) {
    if (player.ActiveInventory != null) player.ActiveInventory = null;
    else inventory[game.inv_activated].RunInteraction(eModeLookat);
  }

Racoon

2) I don´t really understand the scripting. I tried to make it work somehow by putting
Code: ags
lblDescription.Text = Game.GetLocationName(mouse.x, mouse.y);

in Rep.ex. in the global script and
Code: ags
 if (lblDescription.Text == hMaat.Name && MaatLooked==true) lblDescription.Text = "Maat"; 

in the Rep.ex. room script, but it does not work. Before I make my next game I will watch some more basic scripting videos on youtube, but I think for this one I need to keep it really simple :D

3) Hm, I tried to use your code after enabling custom inv click handling, but now I can not pick up item from the inventory anymore nor look at them.

Matti

#17
Put both lines in the global script like this:

Code: ags

lblDescription.Text = Game.GetLocationName(mouse.x, mouse.y);
if (lblDescription.Text == hMaat.Name && MaatLooked==true) lblDescription.Text = "Maat"; 


Just for clarification:
The first line makes sure that the label called "lblDescription" shows the name of the location the mouse is hovering over.
The second line changes the name of the specific hotspot hMaat to "Maat" in case the bool MaatLooked is set to true.
(EDIT: to be precise: it doesn't change the name, but it changes what the label displays)

Please always say what exactly doesn't work, so it's easier to find the solution.

Racoon

Sorry, I thought it would not work at all because I tried to make the label in a Gui like the Displaytext Gui, well it was a mess.

But now that I just put hte new label in the statusline, the Hotspot Descriptions show up just fine. But I can not put
Code: ags
if (lblDescription.Text == hMaat.Name && MaatLooked==true) lblDescription.Text = "Maat"; 

in the global script, because it says GlobalScript.asc(61): Error (line 61): undefined symbol 'hMaat'.


Matti

Right, sorry. Of course you have to put it in the room's script (roll).

Glad it works now.

SMF spam blocked by CleanTalk