Forum Topic: AS3 Game Question

(86 views • 1 reply)

This topic is 1 page long.

<< < > >>
None

bcapecci

Reply To Post Reply & Quote

Posted at: 11/3/09 10:43 PM

bcapecci NEUTRAL LEVEL 06

Sign-Up: 03/07/08

Posts: 300

I'm trying to add 10 enemies and when I shoot each of them, they explode. What's happening now is there is 10 enemies being added to the screen and only 1 of them can be destroyed. All my bullets are being pushed in bulletArray and the collisions are all fine. There is no way of telling which one the explodeable enemy is, but I used to have some basic code that made them follow the player which would only be applied to one of them just like this explosion is. Suggestions? I thought of perhaps pushing the enemies to an array but am wondering if there if an easier way because I really resent being an array hoar. Why can't I create enemies like I roughly did in the following example? Thanks. By the way I'm mostly curious why it won't work not how to fix it but those might go hand in hand. I know pushing to an array works.

for (var j:int = 0; j < 10; j++)
{
	var follow:Follower = new Follower();
	addChild(follow);
	var randomY:int = (Math.random()*500);
	var randomX:int = (Math.random()*650);
	follow.x = randomX;
	follow.y = randomY;
}

for (var i:uint=0; i<bulletArray.length; i++)
	{
		if (collisiondetection.isColliding(follow, bulletArray[i], 1))
		{
			for (var h:Number=0; h<20; h++) 
			{
				makeExplosion();
			}
			removeChild(follow);
		}
	}

None

Fion

Reply To Post Reply & Quote

Posted at: 11/3/09 11:02 PM

Fion LIGHT LEVEL 34

Sign-Up: 08/21/05

Posts: 2,375

The reason it only works for one is because the code goes through the first loop attaching followers using the Follower class by using the variable follow. At the end of the loop follow has the value of the very last Follower attached, hence this is the one that the collision is working for. You best bet would be to use an array or container to attach your followers.


All times are Eastern Standard Time (GMT -5) | Current Time: 12:42 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!