Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-28-2012, 05:27 AM   #1
redterror117
Registered User
 
Join Date: Mar 2012
Posts: 3
Default [AS3] Creating Arrays to Spawn Multiple Movieclips?

I want to be able to spawn multiple enemies for a scrolling flier game I'm working on for college (about 4-5 enemies), and I figured the easier way to handle their creation is through an array. Currently all of my objects (except for myScore) are imported as MovieClip files. Right now this is what I have for enemy-associated code:

Code:
var fEnemy:FEnemy = new FEnemy();

addChild(fEnemy);
fEnemy.x = 0;
fEnemy.y = Math.random() * 150 + 80;

//---Saucer Animation---//
fEnemyMoves();

function fEnemyMoves():void
{
	//fEnemySpeed = (Math.ceil(Math.random() * 6 + 1));//
	fEnemy.x = (Math.ceil(Math.random() * 6)) + 640;//
	fEnemy.y = (Math.ceil(Math.random() * 330)) + 50;//
	Tweener.addTween(fEnemy, 
					 {x:-50, 
					 time:fEnemySpeed,
					 transition:"linear",
					 onComplete:fEnemyMovesLoops}); 
}

function fEnemyMovesLoops():void
{
	//fEnemySpeed = (Math.ceil(Math.random() * 6 + 1));//
	fEnemy.x = (Math.ceil(Math.random() * 6)) + 640;//
	fEnemy.y = (Math.ceil(Math.random() * 330)) + 50;//
	Tweener.addTween(fEnemy, 
					 {x:-50, 
					 time:fEnemySpeed,
					 transition:"linear",
					 onComplete:fEnemyMoves}); 
}
//---End Saucer Animation---//

fireBall.addEventListener(Event.ENTER_FRAME, killEnemy);
function killEnemy(evt:Event): void
{
	if(fireBall.hitTestObject(fEnemy))
	{
		fireBall.removeEventListener(Event.ENTER_FRAME, fireFBall);
		fireFlag = 0;
		fEnemyMoves();
		scores++;
		if (scores == 3)
		{
			stop();
			gotoAndPlay(6);
		}
	}
	myScore.score_txt.text = "score:" + String(scores);
}

Now, if I change the original declaration to:
Code:
for(var i:int = 0; i<3; i++)
{
	var fEnemy:FEnemy = new FEnemy();
	addChild(fEnemy);
	fEnemy.x = 0;
	fEnemy.y = Math.random() * 150 + 80;
}
only one of the enemies will spawn normally. The other two appear, but they only hang around at the other end of the screen. I dont recall the code, but I had been able to (at one point) get all three enemies to start from the right end and go all the way over to the left, but then the game continued with spawning only one enemy again. We haven't learned much about arrays in our classes unfortunately, so I was wondering if I could get advice here.
redterror117 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:31 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.