Jump to content
Search Community

Throwprops end point array

boy2k test
Moderator Tag

Recommended Posts

Hi Guys,

Just trying to work out why i can't give ThrowProps an Array of end points for it to snap to onComplete.

works fine in JS but doesnt seem to work in AS3.

var endPoints:Array = new Array(-20, 50, 120, 190, 260, 330, 400, 470, 540, 610);

TweenMax.to(mc, 5, { throwProps:{x:{velocity:500, end:endPoints}  },  ease:Strong.easeOut, onUpdate:checkPosX, onComplete:doTrace});

Any ideas? 

 

Link to comment
Share on other sites

Ok so i seem to have left out most of the important info lol... sorry busy week!

 

i am trying to animate a block of 9 70x70 squares which are part of a 9x9 grid.

Each brick can move the entire row either horizontally or vertically... basically a 2d rubics cube :)

 

So i start the throwprops and then once a square goes either past the first or last points in the endPoint array i move it forward or backward by 630. I think this x position adjustment is throwing off the end: for the throwprops tween. is there a way to make the tween recalculate?

 

here is a very simple script to explain.

import flash.display.MovieClip;
import flash.geom.Point;
import com.greensock.*;
import flash.events.MouseEvent;
import com.greensock.plugins.*;
import com.greensock.easing.*;


var bricks:Array = new Array(brick0, brick1, brick2, brick3, brick4, brick5, brick6, brick7, brick8);

var bounds:Point = new Point(-20, 610);

var speed:int = 0;
var endPoints:Array = new Array(-20, 50, 120, 190, 260, 330, 400, 470, 540, 610);

TweenPlugin.activate([ThrowPropsPlugin]);

function doTween() {
	trace("doTween called.")
	for( var i:int = 0; i < bricks.length; i++) {
		var mc:MovieClip = bricks[i] as MovieClip;
		
		if( i == 0 ) {
			TweenMax.to(mc, 5, { throwProps:{x:{velocity:500, min:endPoints[0], max:endPoints[endPoints.length -1], end:endPoints}  },  ease:Linear.easeNone, onUpdate:checkPosX, onComplete:doTrace});
		} else {
			TweenMax.to(mc, 5, { throwProps:{x:{velocity:500, min:endPoints[0], max:endPoints[endPoints.length -1], end:endPoints}  },  ease:Linear.easeNone, onUpdate:checkPosX});
		}
	}
	
}

function doTrace() {
	for( var i:int = 0; i < bricks.length; i++) {
		var mc:MovieClip = bricks[i] as MovieClip;
		trace("mc.x:"+mc.x)
	}
}

function checkPosX() {
	for( var i:int = 0; i < bricks.length; i++) {
		var mc:MovieClip = bricks[i] as MovieClip;
		if( mc.x > bounds.y) {
			mc.x -= ( 630 );
		}
		if( mc.x < bounds.x) {
			mc.x += ( 630 );
		}
	}
}


doTween()
stop();

Link to comment
Share on other sites

Yeah, that would definitely mess with the tween! :) 

 

I'm a little confused about why you're altering mc.x in the onUpdate like that, especially if you already specified the max/min values in the tween itself. In other words, it almost seems like you're duplicating the work there. Was it exceeding the bounds for some reason when you applied the max/min values in the tween itself? 

 

It'd be super helpful to see an FLA that we could publish to see what's going on (as simple as possible please). 

 

Also, what version of ThrowPropsPlugin are you using? This is a VERY important question. I asked last time but didn't see an answer. 

Link to comment
Share on other sites

Hi Jack,

Thanks for getting back to me i know its a weekend, much apreciated :)

 

The version i have currently is VERSION: 12.0.9

 

The reason i am altering the x on update is so the square loops in for one side to the next. So the user can scroll the line left or right and it will loop until the squares slow down. I am using onupdate to then bring the other squares on the line along with it.This is because the line can be tweened horizontally or vertically and the tween will be started from one of the squares in a 9x9 grid on finger press. 

 

I'm drawing up some examples for mobile games to try and get some funding for them for a local company.

 

I have included a test file for the tween here:
download.


Thanks :)

Link to comment
Share on other sites

You've got a stale version of ThrowPropsPlugin - it's up to 12.0.16 now. I suspect that's why the "end" snapping isn't working - that feature didn't exist a while back. 

 

Also, if you're trying to apply some custom wrapping logic, you might want to consider tweening a generic object, and then use an onUpdate to apply whatever logic you want and apply the new values to the real object. Just an idea. 

Link to comment
Share on other sites

Ok Jack thanks for the reply, i will get the latest version and give that a whirl. 

Good idea on the tweening of a generic object i will add that in and let you know how i get on.

 

:)

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...