Help with Recycling & Interpolate ??

himsaxhimsax Member Posts: 3
edited November -1 in Working with GS (Mac)
Hello All

In my project I want to make actors appear randomly from the top of the screen and move to centre. I also want them to get destroyed on clicking.
In order to achieve this I am recycling 1 actor and using interpolate to get it to move to the centre. The trouble is that it won't go back to its starting position when I click on it. It will continue to move to the centre of the screen.

Is there a way I can cancel the interpolate midway?
(tried this with a Boolean attribute but did not succeed.)

I did try doing this with the "Move to" behaviour but found it to be very inconsistent. The actor did go back to its starting position upon clicking but would not move to the centre of the screen again.

Can this be achieved using Interpolate or will I have to revert to spawning and destroying :-(

Any help would be appreciated.

Thanks.

Comments

  • DrGlickertDrGlickert Member Posts: 1,135
    Interpolate cannot be interupted. It will always "finish what it started."

    You'll have to chose a different behavior type than Interpolate if you want to recycle your actors.
  • entersimonentersimon Member, PRO Posts: 273
    Actually, you can use a constrain to "interrupt" an interpolate. Although I don't know exactly what's going on inside the code, I'm guessing constrain holds higher priority.

    Here's an example to show you how it works, and hopefully you'll be able to see a way to make it work out for you.

    Make 2 actors and name one Button

    Make a boolean global attribute called button pressed

    In the Button actor create a rule that says if actor receives event - touch - is - pressed -
    change attribute game.button pressed to "true"
    Otherwise
    change attribute game.button pressed to "false"

    In the Other actor you will create 2 rules.

    1st rule:
    When attribute game.button pressed is true
    interpolate self.color.alpha to 0 for a duration of 2 seconds

    2nd Rule:
    When attribute game.button pressed is false
    constrain attribute self.color.alpha to 1

    Now if you press and hold the button, the first actor will interpolate its alpha until you no longer hold down the button.

    True, it's adding a constrain to the equation, which if over used has negative effects on RAM usage, but it may just be the exact effect you're looking for!
  • himsaxhimsax Member Posts: 3
    Thanks for the replies guys but I seemed to have solved my problem.

    The inconsistent "Move to" behaviour was because I was making the actor go back to its starting 'y' position but a random 'x' position.
    Now by specifying the exact exact starting 'x' & 'y' coordinates to go back to it works perfectly fine.
Sign In or Register to comment.