Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Layer opacity / subframes opacity ?  (Read 5160 times)

0 Members and 1 Guest are viewing this topic.

Atelier Sentô

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 52
    • View Profile
    • Atelier Sentô
Layer opacity / subframes opacity ?
« on: February 05, 2014, 10:11:02 AM »

Hello,

I need your help. I'm not good at programming and I have this little problem:
I'm wondering if it's possible to change the opacity of an entire layer.

Per example, when the player opens a close-up layer, it smoothly becomes visible.
When the player closes it, it smoothly becomes invisible.

I've made a test with the  AlphaColor command :

Code: WME Script
  1. on "LeftClick"
  2. {
  3.   var layer = Scene.GetLayer("closeup_winch");
  4.   layer.Active = true;
  5.   layer.AlphaColor = MakeRGBA(255, 255, 255, 50);
  6.   Sleep (100);
  7.   layer.AlphaColor = MakeRGBA(255, 255, 255, 100);
  8.   Sleep (100);
  9.   layer.AlphaColor = MakeRGBA(255, 255, 255, 150);
  10.   Sleep (100);
  11.   layer.AlphaColor = MakeRGBA(255, 255, 255, 200);
  12.   Sleep (100);
  13.   layer.AlphaColor = MakeRGBA(255, 255, 255, 255);
  14. }

And the FadeIn command:

Code: WME Script
  1. on "LeftClick"
  2. {
  3.   var layer = Scene.GetLayer("closeup_winch");
  4.   layer.Active = true;
  5.   layer.FadeIn(500, 255, 255, 255, 0);
  6. }

Both didn't work.
Is there anything else I can try?

Or maybe it's just not possible?

Thank you for your help!
« Last Edit: February 18, 2014, 04:03:54 PM by Atelier Sentô »
Logged

ciberspace

  • Regular poster
  • ***
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 116
    • View Profile
    • Tele Juego
Re: Layer opacity?
« Reply #1 on: February 06, 2014, 03:30:15 PM »

Atelier Sentô

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 52
    • View Profile
    • Atelier Sentô
Re: Layer opacity?
« Reply #2 on: February 08, 2014, 09:30:29 AM »

Thank you for your answer!

I've spent some time today, studying the flashlight script, but I couldn't find a way to solve my problem.
I'll continue to think about it.
Maybe I'll find the answer later!
Logged

2.0

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 217
    • View Profile
Re: Layer opacity?
« Reply #3 on: February 08, 2014, 01:45:34 PM »

Layer has no AlphaColor property as well as has no FadeIn() method.
Try to use such code:

Code: WME Script
  1. function SetAlpha(_object, _alpha)
  2. {
  3.   _object.AlphaColor = MakeRGBA(255, 255, 255, _alpha);
  4. }
  5.  
  6. on "LeftClick"
  7. {
  8.   var layer = Scene.GetLayer("closeup_winch");
  9.   var i;
  10.  
  11.   for (i=0; i<layer.NumNodes; i=i+1)
  12.     SetAlpha(layer.GetNode(i), 0);
  13.  
  14.   layer.Active = true;
  15.  
  16.   for (var a=5; a<=255; a=a+50)
  17.   {
  18.     for (i=0; i<layer.NumNodes; i=i+1)
  19.       SetAlpha(layer.GetNode(i), a);
  20.     Sleep(30);
  21.   }
  22. }
« Last Edit: February 08, 2014, 01:47:44 PM by 2.0 »
Logged

Atelier Sentô

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 52
    • View Profile
    • Atelier Sentô
Re: Layer opacity?
« Reply #4 on: February 09, 2014, 09:51:18 AM »

Thank you 2.0!

I've tested the code in my game: the result is perfect!
Exactly what I was looking for.
I can't wait to implement it to every close-up layer in the game.
I will also take time to study it so I'll become better in scripting!

Many many thanks for your help!
Logged

Atelier Sentô

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Posts: 52
    • View Profile
    • Atelier Sentô
Re: Layer opacity?
« Reply #5 on: February 18, 2014, 04:03:24 PM »

After more tests, I must admit that, even if the script works perfectly, the result doesn't look good.
The reason is very simple:
On a close-up layer there are a background and several nodes above.
When, per example, the background opacity is set on 100, the nodes are set on 100 + 100 (=the background below) : the opacity level of the nodes is added to the opacity level of the background.

So when the script is executed, the opacity changes like this:
background : 5 / Nodes : 5 + 5=10
background : 55 / Nodes : 55 + 55 = 110
background : 105 / Nodes : 105 + 105= 210
...

The nodes appear 2x faster than the close-up background.
The only way I see to get rid of that problem would be to cut holes in the close-up background and put the nodes exactly above those holes.
But is sounds too complicated.
So I'll just forget about having the close-up fade-in / fade-out.


I have another question about opacity.
Is there a way to change opacity for a subframe?

My heroine is a Japanese girl. So everytime she enters a house, she is supposed to take off her shoes.
My idea was to add her shoes as subframe and put the AlphaChannel to 0 everytime she's inside a house.
So there would be no need to load a new actor.

I've tried to do it this way:

1. I've added a Custom Property to the floor named "xShoes" which values are "shoes" when the character is outside and "feet" when she is inside.

2. On the frames of the actor's animation, I add a subframe of the naked feet and a subframe of the shoes.
Then I add a event called "EventShoes" and I attach this script to the sprites:

Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3.  
  4. ////////////////////////////////////////////////////////////////////////////////
  5. //on "event"
  6. //{
  7. //  ...
  8. //}
  9.  on "EventShoes"
  10. {
  11. // get a region the actor is standing in
  12. var RegShoes = Scene.GetRegionAt(this.X, this.Y);
  13.  
  14. var frame = this.CurrentFrame;
  15. var subframe01 = frame.GetSubframe (0);
  16. var subframe02 = frame.GetSubframe (1);
  17.  
  18. if (RegShoes!=null)
  19.   {
  20.    switch(RegShoes.xShoes)
  21.    {
  22.      case "shoes":
  23.          subframe01.AlphaColor = MakeRGBA(255, 255, 255, 0);
  24.          subframe02.AlphaColor = MakeRGBA(255, 255, 255, 255);
  25.      break;
  26.  
  27.  
  28.      case "feet":
  29.          subframe01.AlphaColor = MakeRGBA(255, 255, 255, 255);
  30.          subframe02.AlphaColor = MakeRGBA(255, 255, 255, 0);
  31.      break;
  32.    }
  33.    }
  34. }

As you can see, I used the script for implementing footsteps sounds.
But I don't really understand how to call SubFrames.

And... nothing happens when I play the game.
My script is obviously all wrong.

Is there a way to fix it?
Or maybe it's just impossible to change the opacity of a subframe?

Thank you!
Logged
 

Page created in 0.093 seconds with 23 queries.