Jump to content
Search Community

need help greensock v11 throwprop plugin

Asteroids test
Moderator Tag

Recommended Posts

import com.greensock.*;
import com.greensock.plugins.*;
import com.greensock.easing.*;
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.utils.*;
TweenPlugin.activate([ThrowPropsPlugin]);
var t1:uint,t2:uint,y1:Number,y2:Number,x1:Number,x2:Number,xOffset:Number,yOffset:Number;
mc_square.addEventListener(MouseEvent.MOUSE_DOWN, start_drag);
function mouseMoveHandler(event:MouseEvent):void
{
mc_square.y = this.mouseY - yOffset;
mc_square.x = this.mouseX - xOffset;
var t:uint = getTimer();
if (t - t2 > 50)
{
 x2 = x1;
 x1 = mc_square.x;
 y2 = y1;
 t2 = t1;
 y1 = mc_square.y;
 t1 = t;
}
event.updateAfterEvent();
}
function start_drag(e:MouseEvent):void
{
TweenLite.killTweensOf(mc_square);
x1 = x2 = mc_square.x;
xOffset = this.mouseX - mc_square.x;
y1 = y2 = mc_square.y;
yOffset = this.mouseY - mc_square.y;
t1 = t2 = getTimer();
mc_square.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
mc_square.stage.addEventListener(MouseEvent.MOUSE_UP, stop_drag);
}

function stop_drag(e:MouseEvent):void
{
mc_square.stage.removeEventListener(MouseEvent.MOUSE_UP, stop_drag);
mc_square.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
var time:Number = (getTimer() - t2) / 1000;
var xVelocity:Number = (mc_square.x - x2) / time;
var yVelocity:Number = (mc_square.y - y2) / time;
ThrowPropsPlugin.to(mc_square, {throwProps:{y:{velocity:yVelocity, resistance:600},x:{velocity:xVelocity, resistance:600}}, ease:Strong.easeOut}, 1, 0.3, 1);
}

 

this is my code

 

i need to bound object on stage

 

thanks you for help and sorry for my bad english

Link to comment
Share on other sites

I'm sorry I don't know what you mean by bound object on stage.

Do you need the object being thrown to stay within the bounds of the stage?

If so you can use min and max values in your ThrowProps tween.

Take a look at the docs for more info.

 

http://api.greensock.com/as/com/greensock/plugins/ThrowPropsPlugin.html

 

The syntax looks like this:

 

ThrowPropsPlugin.to(mc, {ease:Strong.easeOut, throwProps:{y:{velocity:yVelocity, max:bounds.top, min:bounds.top - yOverlap, resistance:200}}}, 10, 0.25, 1);

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