Fade in, fade out without changing scenes

TercTerc Member Posts: 13

Hi. I've been using interpolate to fade actors in and out, then changing scenes. This is fine, but what if I don't want to change scenes?

I start by setting the prototype actor's alpha to zero. Then I create this rule:

When attribute self.color.alpha = 0
Interpolate attribute self.color.alpha to 1
Duration 3 seconds

This makes the actor fade in at the start of the scene.
Then I create this rule:

When actor receives event touch is pressed
Interpolate attribute self.color.alpha to 0
Duration 3 seconds

Timer: after 3 seconds
Change scene

This makes the actor fade out and changes the scene.

It works great.

But if I don't change scenes, what occurs is an endless loop of the actor fading in and fading out. This makes sense because every time you click on the actor and the actor's attribute self.color.alpha = 0, then it Interpolates self.color.alpha to 1, duration 3 seconds. Over and over.

Can I get an actor to fade in to start the scene, fade out when clicked, stay faded out, and never have to change scenes?

Thanks.

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    @Terc said:
    Can I get an actor to fade in to start the scene, fade out when clicked, stay faded out, and never have to change scenes?

    Fade in:

    Interpolate alpha to 1.

    . . . . .

    Fade out:

    When touch is pressed - Interpolate alpha to 0.

  • TercTerc Member Posts: 13

    But as I explained above, when touch is pressed and you interpolate alpha to 0, it triggers the first rule:

    When attribute self.color.alpha = 0
    Interpolate attribute self.color.alpha to 1
    Duration 3 seconds

    Which causes the actor to fade right back in.

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2014

    @Terc said:
    But as I explained above, when touch is pressed and you interpolate alpha to 0, it triggers the first rule

    When attribute self.color.alpha = 0

    Interpolate attribute self.color.alpha to 1
    Duration 3 seconds

    Which causes the actor to fade right back in.

    Yes, your code causes the actor to fade back in, so use the code I posted above instead.

  • TercTerc Member Posts: 13

    Sorry Socks. I'm either explaining myself poorly or I'm not understanding you.

    It seems to me that I already am using your code. I thought I was already doing exactly what you were suggesting.

    Is my mistake that I'm setting the prototype's alpha to 0? I think what I'm not understanding is what triggers your first rule; the "fade in" rule.

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2014

    @Terc said:
    Sorry Socks. I'm either explaining myself poorly or I'm not understanding you.

    It seems to me that I already am using your code. I thought I was already doing exactly what you were suggesting.

    You are doing this:

    When attribute self.color.alpha = 0
    Interpolate attribute self.color.alpha to 1
    Duration 3 seconds_

    When actor receives event touch is presse_d
    Interpolate attribute self.color.alpha to 0
    Duration 3 seconds

    . . . . .

    I am suggesting this:

    Fade in: Interpolate alpha to 1
    Fade out: When touch is pressed - Interpolate alpha to 0

    . . . . . 

    There are some pretty obvious differences !?

    @Terc said:
    Is my mistake that I'm setting the prototype's alpha to 0?

    If you want your actor to start with its alpha set to 0 (invisible) then you should set it to 0.

    @Terc said:
    I think what I'm not understanding is what triggers your first rule; the "fade in" rule.

    Nothing ! You don't need to trigger a rule, it will just run when you start the game.

  • TercTerc Member Posts: 13

    All right. I understand now. I needed to remove my first line:

    When attribute self.color.alpha = 0

    Thanks for your help.

  • SocksSocks London, UK.Member Posts: 12,822

    @Terc said:
    All right. I understand now. I needed to remove my first line:

    Thanks for your help.

    Yep ! There's no real need for that rule.

  • TercTerc Member Posts: 13

    Now I want to rediscover the forum post or youtube video that instructed me to include that rule. It should be amended to include the fact that that rule is not needed. I'm still very new to GS so I follow whatever instructions I receive as faithfully as I can.

  • SocksSocks London, UK.Member Posts: 12,822

    @Terc said:
    Now I want to rediscover the forum post or youtube video that instructed me to include that rule. It should be amended to include the fact that that rule is not needed.

    It might have been needed in the particular scenario the tutorial was explaining ?

Sign In or Register to comment.