small medium large xlarge

Generic-user-small
29 Mar 2018, 23:15
guy dude guy (13 posts)

For some reason my Tween makes the shapes I’m trying to move skip forward for a split second, then it runs the tween. The skip looks ugly and wrong (because it is) but I don’t know how to stop it. Here is a link to the game: (use arrow keys) click

Chris_strom_headshot_200_pragsmall
31 Mar 2018, 00:47
Chris Strom (278 posts)

I can certainly understand why you had a tough time figuring this one out. It took me a while too :)

The problem is on line 225 and 226 when end is assigned:

.

    if (toMove === 0) end = {X: av.center.position.x += toMult * baseSize, Y: av.center.position.y};
    else end = {X: av.center.position.x, Y: av.center.position.y += toMult * baseSize};

.

The problem is the +=. If you change those to just +, then it will work like you expect:

.

    if (toMove === 0) end = {X: av.center.position.x + toMult * baseSize, Y: av.center.position.y};
    else end = {X: av.center.position.x, Y: av.center.position.y + toMult * baseSize};

.

Both + and += are setting the end value correctly. The problem is that += is also changing the av’s position. So, right before the tween starts, av’s position set to the end position – av jumps to the end. Then the tween moves the av back to the start position and tweens like normal. That’s why is jumped like it did.

Hope that makes sense. Let me know if you have any other questions.

-Chris

Generic-user-small
09 Apr 2018, 18:25
guy dude guy (13 posts)

I’m very thankful for your help, it worked great! Ya I understand that and see what I did wrong… now I know for next time!