[Behavior] LiteTween

Post your completed addons to share with the community

Post » Thu Jun 05, 2014 8:16 am

Hi Lunarray,

Thanks for your wonderful behavior.

I was interested in the elastic easing function to tweak it a little. After going through the forest of it's code:

Code: Select all
    var s=1.70158;var p=0;var a=c;
    if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
    if (a < Math.abs(c)) { a=c; var s=p/4; }
    else var s = p/(2*Math.PI) * Math.asin (c/a);
    return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;


It turned out it could be simplified as this:

Code: Select all
    if (t==0) return b;  if ((t/=d)==1) return b+c;
    return c * Math.pow(2,-10*t) * Math.sin( (t*3-0.25)*2*Math.PI ) + c + b;


It's also possible to do just this:
Code: Select all
     t /= d;
     return c * Math.pow(2,-10*t) * Math.sin( (t*3-0.25)*2*Math.PI ) + c + b;


but then it will be a little off at t == d ( around 0.1% )

All these conditions and extra vars are either someone's joke or the result of JS obfuscation/deobfuscation.
B
9
S
3
Posts: 55
Reputation: 767

Post » Fri Jun 06, 2014 1:13 am

@suntemple

Ah that one? actually the s and p variable and all can be changed to skew the curve of the elastic behaviour, i'm just making it to 1.70158 to match the default just like the penner's equation (same also with bounce and back). If I removed it all together, I wouldn't be able to use the s and p variable later on if I decided to expose those parameter one day. If you want you could look at the original penner's equation and you'd see that I didn't make any significant change on the original source.

I can just make it to what you've written to make it much more optimized, but it doesn't make it run any faster during runtime. I used lookup tables, so that calculation would only needed to be done once (precalculation) and it wouldn't ever need to be calculated anymore.

TL;DR: I'm not trying to make it hard to read or anything about those code sections, I just copied it from the original source :oops:. If I changed it to your version, it definitely would run faster, but I am thinking of exposing those variables one day.
B
32
S
5
G
1
Posts: 178
Reputation: 3,501

Post » Fri Jun 06, 2014 1:38 am

Okay, makes sense then, thanks for clarification :)
B
9
S
3
Posts: 55
Reputation: 767

Post » Thu Jun 12, 2014 2:51 am

Question: What are the list of attributes for "Initial" - "current" is default. Curious if "fromTo" or other methods like TweenMax/Lite are available.

EDIT: Nevermind. I switched to LiteTween. Looks like Initial is no longer used.
B
7
S
1
Posts: 48
Reputation: 1,729

Post » Sat Jun 28, 2014 6:30 pm

congratulations for this plugin :D it's one of my favourites :D

There is an error in eventsheet option "Set Target" where "size" in target is missing (there is no souch option)
B
13
S
3
Posts: 73
Reputation: 802

Post » Sun Jun 29, 2014 6:34 am

Oh, Size tween actually accepts two parameter which is width and height, you can or should use set target width and set target height for that...
B
32
S
5
G
1
Posts: 178
Reputation: 3,501

Post » Sun Jun 29, 2014 8:46 am

Added a little change for ppl who got frustated with always having to 'set target' when starting tween. Download on the first page.

Explanation about the frustration:

1. Say we have an apple sprite on coordinate (50,50) with Litetween behaviour and DragDrop on it.
2. We set target to x: 100 relative and y: relative on the "On Layout Start" condition.
3. When apple is mouse right-clicked, we set it to start the tween.

What supposed to happen for MOST people:

Apple dragged to 100, 100 using dragdrop
Apple right clicked
Apple moves to 200, 200

What really happened:

Apple dragged to 100, 100 using dragdrop
Apple right clicked
Apple teleports to 50,50 then moves to 150,150

How to fix it in the old litetween:
Do not set target x:100, y:100 in the start layout, force target recalculation on the On Right mouse click, just before starting tween.

Some people complains to me about this. This is not a bug, but a rather poor design due to my inconclusiveness -.- (sorry).
So, I added a little fix on the litetween, when you are starting tween, you can force recalculation using the new option, the default is the old litetween behaviour.

PS: For people who are affected by this, I hope you guys can give me input about how I should tackle this.
B
32
S
5
G
1
Posts: 178
Reputation: 3,501

Post » Fri Jul 04, 2014 8:46 pm

First off, thank you! This is an essential function and I could hardly use C2 without it. :)

Second, I think I found a bug when working with mirrored or flipped sprites. Moving or scaling them with LiteTween un-does the flip or mirror. Is there any way around this?

Example attached.

Thanks! :)
You do not have the required permissions to view the files attached to this post.
B
8
S
1
Posts: 55
Reputation: 466

Post » Sat Jul 05, 2014 4:02 am

@TrickyWidget

Ok, this one should have fixed it, the scale tween vs mirror and flip.

Could you explain the bug about 'Moving' with LiteTween undoing flip/mirror? The code on the position tween have nothing to do with Height or Width, so it shouldn't even affect anything about scale.

PS: Download on the first page like usual
B
32
S
5
G
1
Posts: 178
Reputation: 3,501

Post » Sat Jul 05, 2014 12:01 pm

lunarray wrote:Ok, this one should have fixed it, the scale tween vs mirror and flip.

Wonderful, thank you! :)

lunarray wrote:Could you explain the bug about 'Moving' with LiteTween undoing flip/mirror? The code on the position tween have nothing to do with Height or Width, so it shouldn't even affect anything about scale.

Ah, my mistake! Looking back over my code, the moving I was thinking of also involved scaling. So it seems that was the whole thing. Sorry for the trouble.

Thanks again for your great work!
Last edited by TrickyWidget on Mon Jul 07, 2014 12:04 pm, edited 1 time in total.
B
8
S
1
Posts: 55
Reputation: 466

PreviousNext

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 1 guest