USERNAME:
PASSWORD:
Save Info!
Logging in…
This topic is 1 page long.
[ Profile | Posts | Contact ]
Posted at: 6/29/09 09:14 PM
Sign-Up: 11/27/08
Posts: 31
So the problem I have right now is I'm using some code I was taught by a friend of mine to generate enemies. How its set up is that that enemy is put into a movieclip and then a new variable is made to be a display object of each child of that movieclip. So that way I only have to tell all of them to do something once. Unfortunately when I want only one enemy to do something, they all do it. How can I make the one enemy i'm influencing be the only one to do something, when the only way I can reference the enemies references them all?
Posted at: 6/29/09 09:19 PM
Sign-Up: 09/09/07
Posts: 3,201
At 6/29/09 09:14 PM, Rudder21 wrote: So the problem I have right now is I'm using some code I was taught by a friend of mine to generate enemies. How its set up is that that enemy is put into a movieclip and then a new variable is made to be a display object of each child of that movieclip. So that way I only have to tell all of them to do something once. Unfortunately when I want only one enemy to do something, they all do it. How can I make the one enemy i'm influencing be the only one to do something, when the only way I can reference the enemies references them all?
What do you mean by "referencing them all"? If you're giving them separate instance names, like you should be doing, then you can access each of them individually.
I code in AS2, in case I forgot to mention it.
Posted at: 6/29/09 09:30 PM
I have around ten enemies on the screen at a given time, and new ones will pop up within seconds of the last one. This is what I want, and making a new instance name for everyone of them. and having to write those conditions for each one would be a huge huge HUGE time consumer
Posted at: 6/29/09 09:31 PM
Sign-Up: 11/11/07
Posts: 561
Show me the enemy creation code.
Mibbygames.com panterA
Posted at: 6/29/09 09:40 PM
var enemy: Enemy; /*enemy is my animation*/ addEventListener(TimerEvent.Timer,genera teEnemies); addEventListener(Event.ENTER_FRAME, updateEnemies); function generateEnemies(e:TimerEvent): void { enemy = new EnemyChuters; enemy.x = Math.round(Math.random()*550); enemy.y = 550; enemyClip.addChild(enemy); } } function updateEnemies(e:Event): void { for (var i: int = 0; i < enemyClip.numChildren; i++) { var E:DisplayObject = enemyClip.getChildAt(i); /*So if I want my enemies to all do the same thing, i tell E to do it e.g. if I wanted them all to move foward id say E.x++;*/ } // end code Its good for making a bunch of them appear on the screen at random or at select times. the problem is interacting with only one of them
Posted at: 6/29/09 10:09 PM
When you make an enemy, add it to an array. When you want to do something to a specific enemy, find it in the array.
Posted at: 6/29/09 10:20 PM
Sign-Up: 10/02/07
Posts: 801
Both of you who posted are fucking retards
You need to add an event listener for the movie clips as they're created
That way, you can handle it using a single function that will account for each movie clip
Posted at: 6/29/09 11:31 PM
Sign-Up: 02/28/04
Posts: 447
At 6/29/09 10:20 PM, polym wrote: Both of you who posted are fucking retards You need to add an event listener for the movie clips as they're created That way, you can handle it using a single function that will account for each movie clip
What's wrong with you? Please watch your language. Don't be so quick to judge people's intellectuality based on your criteria of how things should be done. It would be perfectly acceptable to push the instances into an array for later retrieval. What made you think your way is the only way?
CarlosPerea.com | EGB
Posted at: 6/30/09 07:43 AM
At 6/29/09 10:20 PM, polym wrote: Both of you who posted are fucking retards
Don't be so quick to judge.
At 6/29/09 09:14 PM, Rudder21 wrote: Unfortunately when I want only one enemy to do something, they all do it.
From his post that sounds like exactly what he wants. Then, he could just use a for loop to access them all.
Posted at: 6/30/09 08:04 AM
Sign-Up: 09/10/04
Posts: 3,553
As far as I can see, he already have a loop to iterate on all enemies.
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.
Posted at: 6/30/09 08:08 AM
Would any1 mind showing me what the code might look like for the array method? I just need a visual of how it would look.
Posted at: 6/30/09 09:42 PM
Sign-Up: 08/04/05
Posts: 370
How you do this depends largely on what you are trying to accomplish. If it is something like shooting at a target, then you can use a distance conditional statement to dictate when the enemies fire. For example:
var dist:Number = Math.sqrt(Math.pow(Object1.x-Enemy.x, 2)+Math.pow(Object1.y-Enemy.y, 2)); //Uses the distance formula to calc distance if(dist<50){ //do stuff here }
AS3: Main || AS2: Main
All times are Eastern Standard Time (GMT -5) | Current Time: 10:47 AM
<< Back