Jump to content
Search Community

ThrowPropsPlugin wrap property value

Flammenmensch test
Moderator Tag

Recommended Posts

Hello,

 

I was wondering, is there a way not to increase the property value infinitely, but to reset it back to it's minimum value when it reaches its' maximum and continue tweening?

 

Say, I have an object with a property which I would like to "throw" with my mouse. But the thing is, the valid values for the property are from 0 to 10. So, if the value during the tween exceeds 10, I want it to go back to 0 and continue tweening until it stops.

 

Thanks in advance.

Link to comment
Share on other sites

Hi and welcome to the forums.

 

The API isn't designed to wrap numbers natively but here is a rough idea to try out:

 

import com.greensock.*;
import com.greensock.easing.*;


var myValue:Number = 0;


TweenLite.to(this, 100, {myValue:100, onUpdate:normalize, ease:Linear.easeNone, useFrames:true});


function normalize() {
  trace(int(myValue) + " : "  + int(myValue%10))
}

Here is the output you will get, notice the numbers on the right wrap

1 : 1
2 : 2
3 : 3
4 : 4
5 : 5
6 : 6
7 : 7
7 : 7
8 : 8
9 : 9
10 : 0
12 : 2
13 : 3
14 : 4
15 : 5
16 : 6
17 : 7
17 : 7
18 : 8
19 : 9
20 : 0
21 : 1
23 : 3
24 : 4
25 : 5
26 : 6
27 : 7
28 : 8
29 : 9
30 : 0
...

 

I'm setting useFrames:true just to force 100 updates, its not necessary by any means.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...