views:

52

answers:

1

I've got an array of 10 frogs, and only one jumps. I want them all to jump together or sequentially. Anything is better than one frog jumping. How do I get all the frogs in my array to jump?

WHAT I WANT
Selectable frogs I can control

alt text

//Creates 10 frogs
var enemyArray:Array = new Array();

for (var i:int = 0; i < 10; i++)
{
   var noname:FrogClass = new FrogClass();
   noname.x = i*44; //this will just assign some different x and y value depending on i.
   noname.y = i*22;
   //noname.x = stage.stageWidth/3;
   //noname.y = stage.stageHeight/3;
   enemyArray.push(noname); //put the enemy into the array
   addChild(noname); //puts it on the stage
}

//MOTION "moves display list item"
var value:Number = 0.0;
addEventListener( Event.ENTER_FRAME, onEnterFrame );
function onEnterFrame( e:Event ):void
{
noname.y = 10 + ( Math.sin( value ) * 44 );
value += 0.1;
}

SYMBOL PROPERTIES
NAME "noname"
CLASS "FrogClass"

PROGRAMING RELEVANT
I want to play with arrays and the displayList.

RELATED
Scattering the frogs or using other motions would be interesting

+1  A: 
//MOTION "moves display list item"
var value:Number = 0.0;
addEventListener( Event.ENTER_FRAME, onEnterFrame );
function onEnterFrame( e:Event ):void
{
for (var i:uint = 0; i < enemyArray.length; i++)
{
var enemyFrog:FrogClass = enemyArray[i]; 
enemyFrog.y = 10 + ( Math.sin( value ) * 44 );
}
value += 0.1;
}

This is untested, but should work. You need to move each instance of frog in your array.

jedierikb
Haha, I was literally just about to post an answer that looked like, *exactly* the same! :P
debu
...looks weird:) Keep them coming if you've got any variations on this, I'd like to see. Thanks
VideoDnd
How's it weird? That's how you loop through a for loop, you could use a for-each but there's no real benefit here.
debu
http://farm2.static.flickr.com/1350/1331884159_3c2bcf8d3e_b.jpg
jedierikb
It's awesome! It's a good example for what I'm testing
VideoDnd