Jump to content
GreenSock

MrMiyagi

Physics2DPlugin ?

Recommended Posts

Hi,

 

I just got my really green club plugins which are very nice.

 

I am trying to implement this physics2DPlugin to my project. What is the best way to replace these dots with my own movieclip? Thanks for all answers!

 

Heres the code from the example:

import com.greensock.TweenLite;
import com.greensock.plugins.TweenPlugin;
import com.greensock.plugins.Physics2DPlugin;
TweenPlugin.activate([Physics2DPlugin]); //activation is permanent in the SWF, so this line only needs to be run once.


for (var i:int = 0; i < 60; i++) {
tweenDot(getNewDot(), getRandom(0, 9.75));
}

function tweenDot(dot:Shape, delay:Number):void {
dot.x = 172;
dot.y = 160;
TweenLite.to(dot, 9.75, {physics2D:{velocity:getRandom(70, 370), angle:getRandom(245, 295), 
gravity:380}, delay:delay, onComplete:tweenDot, onCompleteParams:[dot, 0]});
}

function getNewDot():Shape {
var s:Shape = new Shape();
var green:uint = 0 | int(getRandom(80, 256)) << 8 | 0;
s.graphics.beginFill(green, 1);
s.graphics.drawCircle(0, 0, Math.random() * 8 + 5);
s.graphics.endFill();
this.addChild(s);
return s;
}

function getRandom(min:Number, max:Number):Number {
return min + (Math.random() * (max - min));
}

Link to comment
Share on other sites

You'd need to edit the getNewDot() function so that it returns instances of your MovieClip instead of the Shape objects that it currently does. If you have a MovieClip in your library that you want to use, just make sure you export it for ActionScript, give it a class name, and use that class in the place of the Shape object (like "new MyClass()" instead of "new Shape()" in the code). And of course you could get rid of the code in that function that draws the circle.

Link to comment
Share on other sites

  • 9 months later...

Dear GreenSock Team and all,

 

I really thank you for developing so usefull tool like this is.

I'm beginner in flash. So this is really helpfull for me.

But I have small problem, I trying to make small animation with Physics2DPlugin.

Here is code of my fla:

 


stop();

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.Physics2DPlugin;
import com.greensock.plugins.TweenPlugin;
import flash.display.MovieClip;

TweenPlugin.activate([Physics2DPlugin]);



for (var i:int = 0; i < 10; i++) {
tweenTisic(getNewTisic(), getRandom(0, 3));
tweenDvatisice(getNewDvatisice(), getRandom(0, 3));
tweenDvatisice(getNewPettisic(), getRandom(0, 3))
}

function tweenTisic(dot:MovieClip, delay:Number):void {
dot.x = 150;
dot.y = -100;
TweenLite.to(dot, 8, {physics2D:{velocity:getRandom(80, 380), angle:getRandom(245, 295), gravity:400}, delay:delay,rotation:getRandom(0,360), onComplete:tweenTisic, onCompleteParams:[dot, 0]});
}

function tweenDvatisice(dot:MovieClip, delay:Number):void {
dot.x = 350;
dot.y = -100;
TweenLite.to(dot, 8, {physics2D:{velocity:getRandom(80, 380), angle:getRandom(245, 295), gravity:400}, delay:delay,rotation:getRandom(0,360), onComplete:tweenDvatisice, onCompleteParams:[dot, 0]});
}

function tweenPetisic(dot:MovieClip, delay:Number):void {
dot.x = 400;
dot.y = -150;
TweenLite.to(dot, 8, {physics2D:{velocity:getRandom(80, 380), angle:getRandom(245, 295), gravity:400}, delay:delay,rotation:getRandom(0,360), onComplete:tweenDvatisice, onCompleteParams:[dot, 0]});
}

function getNewTisic():MovieClip{
var s:MovieClip = new tisic;
this.addChild(s);
return s;
}

function getNewDvatisice():MovieClip{
var s:MovieClip = new dvatisice;
this.addChild(s);
return s;
}

function getNewPettisic():MovieClip{
var s:MovieClip = new pettisic;
this.addChild(s);
return s;
}

function getRandom(min:Number, max:Number):Number {
return min + (Math.random() * (max - min));
}



TweenMax.from(sverte, 1.5,{x:-700,ease:Elastic.easeInOut, yoyo:true, repeat:1, repeatDelay:3, onComplete:reset});

function reset(){

gotoAndPlay("start");

}

 

There are three "falling" animations and last tweened Movie Clip "sverte" is in higher layer, but falling objects appear in front of object "sverte" and some one is falling behind them. So I don't know why. Please can you help me? As I sayd I'm beginner :oops: .

 

Thank you for reply

Link to comment
Share on other sites

You're trying to affect the stacking order of objects, right? If so, you can addChild() an object to its parent to make it go to the top of the display list or use setChildIndex() to set it to a specific level. Read Adobe's docs to understand the display list a bit better. For example, to put object1 on top of all others, do object1.parent.addChild(object1). To put it on the bottom, do object1.parent.setChildIndex(object1, 0);

Link to comment
Share on other sites

Thank you very much!

This really solved my problem :D

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