Pulsating button indicator

floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

Im using a simple ring to indicate a spot for the user to click on. I would like the ring to gradually come on and off (alpha up and down). I'm thinking interpolate with a timer but I can't seem to get my head around the logic. Heres what I've got....

Inside the circle graphic I've got one attribute.

buttonOn as a boolean

Change attribute: self.color.alpha_to_0

Rule:

When _attribute: game.time_=_2
Change attribute: self.button.on_to_true

Rule:

When _attribute: self.buttonOn_is_true
Timer:
    After 2 seconds    _run to is checked
    Interpolate: self.color.alpha to 1
    for 2 seconds

otherwise

Interpolate: self.color.alpha to 0

But obviously this ain't doing it for me or I wouldn't be asking for help...thanks

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    It could be that game.Time never actually reaches a value of 2. It may be 1.9987 or 2.01568 for example. It should be a bit simpler than that, anyway:

    When attribute self.color.alpha=0
    Interpolate self.color.alpha to 1 [duration: 2 seconds]
    When attribute self.color.alpha=1
    Interpolate self.color.alpha to 0 [duration: 2 seconds]

    Are you wanting it to start two seconds after the game is previewed? And are you wanting any kind of pause between the two interpolations?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    I think I got it...

    Rule: when_attribute game .time_=_2

     change attribute: self.bottonOn _ to_ true
    

    Rule: when_attribute: self.buttonOn_is _true

     Rule:when_attribute self.color.alpha _=_0
    
     Interpolate:self.color.alpha _to_1
     for 2 seconds
    
     Rule:when_attribute: self.color.alpha _=_ 1
     interpolate:self.color.alpha_to_0
     for 2 seconds.
    
  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    Yeah thats it! Mo simple!Thanks tatting!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2015

    Glad to hear it. I'm not sure what you have the self.buttonOn attribute but perhaps you're using that for something else.

    Edit: you're welcome! :)

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MattSodenMattSoden Member Posts: 30

    Taking inspiration from Socks' trig lessons thread - which explained to me (for the first time) how I could visualise Sin and Cos - try constraining the image alpha to thr following to make it pulse:

    Constrain self.color.alpha to abs(sin(self.time*40))
    

    Change the value 40 to a lower number to slow down the pulse and higher to speed it up - then just run this rule after 2 secs.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2015

    Even better, @Matt Soden‌ By the way, with a space in your name you won't receive forum notifications. I'll see if I can remove it ( @MattSoden , there!) but if it doesn't stick, send a private message to @ForumNinja‌.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MattSodenMattSoden Member Posts: 30

    I'll see if I can remove it ( @MattSoden , there!) but if it doesn't stick, send a private message to @ForumNinja‌.

    Cheers tatiang

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    Wow! thats awesome! Works great. Thanks Is a constraint more cpu intensive?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @floatingwoo said:
    Wow! thats awesome! Works great. Thanks Is a constraint more cpu intensive?

    I doubt it. My guess is that constantly interpolating and constantly constraining should be equally intensive.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    Cool thanks!

  • HopscotchHopscotch Member, PRO Posts: 2,782

    I always thought that "constrain" is such an ominous term, as it is just a change attribute behaviour that will execute every code cycle. :)

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    @MattSoden said:
    Taking inspiration from Socks' trig lessons thread - which explained to me (for the first time) how I could visualise Sin and Cos

    Someone made it through the 'course' ! ;)

    @MattSoden said:
    Constrain self.color.alpha to abs(sin(self.time*40))

    This is 'bouncing' the sine wave when it hits zero, maybe that was what you wanted, it looks kinda pulsey after all ! If you wanted to have a dampened return at each end (basically squash the whole range of the sine wave into 1 (as colour channels only operate from 0 - 1 and a sine operates from -1 to 1) . . it would be, constrain alpha to:

    0.5 *sin(self.time *40)+0.5

    Hold on, I feel we need a picture . . . back in a second . . .

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    @MattSoden‌

    The top image is your version that is bouncing the sine wave when it hits zero, the bottom is cutting its range in half and then moving it up by half its height . . . both work as a pulse.

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    Oh yeah thats much nicer Thanks!
    Like a light house on a foggy day....

  • ChunkypixelsChunkypixels Member Posts: 1,114

    Whats the name of the thread with @Socks trig lessons?

    Working on something at the moment that could benefit from a re-education in the subject :)

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    @Chunkypixels said:
    Whats the name of the thread with Socks trig lessons?

    Working on something at the moment that could benefit from a re-education in the subject :)

    It wasn't really a lesson, it was just another thread that got derailed into a sin/cos thing, but was abandoned in the end, there were no saviours.

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    @floatingwoo said:
    Oh yeah thats much nicer Thanks!
    Like a light house on a foggy day....

    Yeah, it's exactly like a lighthouse as its the amount of light you would see if the light source was revolvling.

  • ChunkypixelsChunkypixels Member Posts: 1,114
    edited January 2015

    @Socks yup..but which thread? :)

    I remember liking the sin/cos tutorials/explanations you did, and could do to look at it again....

Sign In or Register to comment.