Jump to content
GreenSock

dsgsgsg

Timeline - place enemies in order

Recommended Posts

Hello,

I have a loop in which I am placing an enemy leader, (the first enemy) and the rest that have position relative to the enemy leader.They all animate over a path.

The Call:



 

createEnemies(2,path02,100, 5,0);
createEnemies(3,path02,100, 5,0);
 

 


The Function:



 

public function createEnemies(enemyNo:int, path:Array, dir:String,offset:int, duration:int, delay:int):void
{
for(var i:uint=1;i<=enemyNo;i++){

if (i==1){

_leaderEnemy = new ShooterEnemy();
_leaderEnemy.x=0;
_leaderEnemy.y=0;
_leaderEnemy.count=enemyNo;

_leaderEnemy.name = "_shooterEnemy"+i;


leaderEnemyArray.push(_leaderEnemy);
tempCont.addChild(_leaderEnemy);
}
else
{

var _shooterEnemy:ShooterEnemy = new ShooterEnemy();


_shooterEnemy.x=0;
_shooterEnemy.y=(offset*(i-1));

_shooterEnemy.name = "_shooterEnemy"+i;
tempCont.addChild(_shooterEnemy)}

}

timeline.append(TweenMax.to(tempCont, duration, {bezier:path,orientToBezier:false, ease:Linear.easeNone}),delay );
}

 

 

Every time I call the three or four times, all the enemies animate at once.

But what I want is the group of enemies moving in their order. i.e. one after another

I am new to timeline and tween max library so any help would be nice.

Link to comment
Share on other sites

It appears you are animating tempCont, and also appending it to the timeline multiple times. 

From what the behavior you are describing as the desired behavior (each enemy animating individually) you should be adding each enemy to the timeline like so

 

 

 

 

timeline.append(TweenMax.to(_shooterEnemy, duration, {bezier:path,orientToBezier:false, ease:Linear.easeNone}),delay );
 

 

Note this doesn't account for _leaderEnemy. You will either have to create a new append call inside your condition for _leaderEnemy OR create a variable that will reference either _leaderEnemy or _shooterEnemy

 

something like

 

 

 

var currentEnemy:*;
f (i==1){


...


currentEnemy = _leaderEnemy;
leaderEnemyArray.push(currentEnemy);
tempCont.addChild(currentEnemy);
}
else
{


...


_shooterEnemy.name = "_shooterEnemy"+i; 
currentEnemy = _shooterEnemy;
tempCont.addChild(currentEnemy)


}


timeline.append(TweenMax.to(currentEnemy, duration, {bezier:path,orientToBezier:false, ease:Linear.easeNone}),delay );
}
 

 

 

Link to comment
Share on other sites

ah, ok, it seems I misunderstood your question. Thanks for the refresher on your project. In that case, from the code you have shown here, I can only guess that all enemies are going into the same tempCont object. I don't see anywhere that a new tempCont is being created for each group of enemies. it also seems that you are creating the animation on tempCont in each iteration of your loop. I think you want something more along the lines of 

 

 

 

creatEnemies() {
//create a temp cont
//loop through creation of enemies
// --- create enemy
// --- place enemy in tempCont
//close loop//add 1 tween of temp cont to timeline after it has been populated with multiple enemies
} 
 

 

Link to comment
Share on other sites

I did as you said:

 

 

 

 

public function createEnemies(enemyNo:int, path:Array, dir:String,offset:int, duration:int, delay:int):void
{

g++;
var tempCont:Sprite=new Sprite();
this.addChild(tempCont);
tempCont.name="temp"+g;

for(var i:uint=1;i<=enemyNo;i++){

if (i==1){

_leaderEnemy = new ShooterEnemy();
_leaderEnemy.x=0;
_leaderEnemy.y=0;
_leaderEnemy.count=enemyNo;

_leaderEnemy.name = "_shooterEnemy"+i;


leaderEnemyArray.push(_leaderEnemy);
tempCont.addChild(_leaderEnemy);
}
else
{

var _shooterEnemy:ShooterEnemy = new ShooterEnemy();


_shooterEnemy.x=0;
_shooterEnemy.y=(offset*(i-1));

_shooterEnemy.name = "_shooterEnemy"+i;
tempCont.addChild(_shooterEnemy)}

}

timeline.append(TweenMax.to(tempCont, duration, {bezier:path,orientToBezier:false, ease:Linear.easeNone}),delay );
}

 

 

 

 

 

 

it does not really change the result. I was looking into naming each tempCont with a different suffix in order to insure that I am adding each group to diff tempCont.

Link to comment
Share on other sites

It still looks like timeline.append() is being called multiple times inside your loop. It appears right afte the else is closed but before the loop is closed.

 

From what I can tell from your description you only need 1 tween each time createEnemies() is called. 

 

Please provide some files that i can test if you need more help with this. Its very difficult and time consuming to have to guess what could be causing the issues. I don't need your full production files, just enough code and assets to test the createEnemies() function.

 

Thanks

Link to comment
Share on other sites

I dont think the timeline was being append muultiple times because i used a trace to check that.

And the good thing I solved the issue although I dont know how I did it. 

 

What I did was this:

 

 

 

public function createEnemies(enemyNo:int, path:Array, dir:String,offset:int, duration:int, delay:int):void
{

for(var i:uint=1;i<=enemyNo;i++){

if (i==1){

var tempCont:Sprite=new Sprite();
this.addChild(tempCont);

_leaderEnemy = new ShooterEnemy();
_leaderEnemy.x=0;
_leaderEnemy.y=0;
_leaderEnemy.count=enemyNo;

_leaderEnemy.name = "_shooterEnemy"+i;


leaderEnemyArray.push(_leaderEnemy);
tempCont.addChild(_leaderEnemy);
}
else
{

var _shooterEnemy:ShooterEnemy = new ShooterEnemy();


_shooterEnemy.x=0;
_shooterEnemy.y=(offset*(i-1));

_shooterEnemy.name = "_shooterEnemy"+i;
tempCont.addChild(_shooterEnemy)}

}

timeline.append(TweenMax.to(tempCont, duration, {bezier:path,orientToBezier:false, ease:Linear.easeNone}),delay );
}

 

See I placed the creation of tempCont where _leaderEnemy was being created, now it is working properly.

 

But could you tell me why that was an issue, I mean either way a new tempCont should be created every time the function is called.

 

:shock:  :shock:  :shock:  :shock:  

Link to comment
Share on other sites

First, my apologies. I hadn't noticed the closing } previously

 

tempCont.addChild(_shooterEnemy)}

 

on the for loop.

 

 

And, yes I'm as puzzled as you why your fixed worked but didn't work the other way. I would of thought too that previously only 1 instance of tempCont was created and added to stage per function call. 

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