Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsI'm a capable coder so am not asking for the code of what I am about to ask, but how to structure it, and how to come about actually doing it.
What I want to happen, is have enemies (MC's) which randomly spawn in a certain place (I can manage controlling where they spawn)
My problem is that I want them to have their own code which they execute, and other objects in the stage must be able to react with them.
I want to know how using a controller MC (or a better way) to cause them to spawn, give them a name which is unique to them, (by adding 1 to the name of the spawned enemy), and have them execute their own code using _global. variables.
Once again, I am not asking for code, just a structure to how to come about doing it (like where to put the code that I want all the mc's of the enemy to spawn with and run)
Thanks for your help, I will mention you in the credits with a link to your Newgrounds Page (or your site) but only if you are helpful in solving my problems.
Thanks NG
Read about classes and arrays. You should create a class file for the different enemies you have, and when you create the enemies on stage you should add them to an array from which you can control them.
You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.
Take a look in these places:
At 12/1/09 06:54 AM, ProfessorFlash wrote: Read about classes and arrays. You should create a class file for the different enemies you have, and when you create the enemies on stage you should add them to an array from which you can control them.
I shall have a look at them, I do understand arrays, but how would an array control them?
Also thanks for the two links Bogoblin.
At 12/1/09 06:57 AM, UndefinedArt wrote:
Also thanks for the two links Bogoblin.
No problem. Bookmark AS: Main. It really comes in handy.
This is just a small ask? but say I was exporting a flash game as an swf, and it had external script, how would I apply the external script to the swf if on a site like newgrounds.
=D
At 12/1/09 06:57 AM, UndefinedArt wrote:
I shall have a look at them, I do understand arrays, but how would an array control them?
Well array doesn't actually 'control' them. If you know arrays you know they are used to store stuff neatly in one variable from which you can access many different values inside of it. So I meant that you can access the enemies easily when they are in an array and then do whatever you want with them.
You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.
Personnaly I would do it this way
var myMc:MovieClip=attachMovie(all the usual stuff and maybe some custom parameter in {} like Xspeed:xxx, EnnemyType:xxx etc)
myMc.onEnteFrame=function(){ your object behavior function call, I usually use a Switch case if I have diferent type of ennemy spawning}
if you want to use array you can use push() to push the new movie clip in an array then use a for loop to asign them a function like this
var myMc:MovieClip=attachMovie(all the usual stuff and maybe some custom parameter in {} like Xspeed:xxx, EnnemyType:xxx etc)
myArr.push(myMc)
onEnterFrame=function(){
myEnnemyFunction()
}
function myEnnemyFunction(){
for(i=0;i<myArr.lenght;i++){
myEnnemyBehavior(myArr[i])
}
}
function myEnnemyBehavior(myEnn:MovieClip){
your ennemy code
}
Thanks guys,
I'll try out these methods.
I'm also wondering, when u duplicate a movieclip, does the movieclip keep all it's code, since I'm probably going to try and have all the movieclip's keep there code, and since the code has to be on the mc itself, does that mean I have to put an mc in an mc, if you know what I mean.
I'd love to hear suggestions on how to attempt that.
You can actually code on the first frame of the clip itself, referencing itself and it will have access to all of the global variables via _root.
Not the most efficient/organized way, but incredibly easy to implement.
Perpetually looking for time to return to the arts.
At 12/1/09 10:27 PM, Johnny wrote: You can actually code on the first frame of the clip itself, referencing itself and it will have access to all of the global variables via _root.
Not the most efficient/organized way, but incredibly easy to implement.
Yes I thought that myself. It is abit messy but I think thats the way I'm gonna go.
Thanks.
via _root.thats the way I'm gonna go.
Shame, good luck with that though
nobody
At 12/2/09 05:41 AM, hdxmike wrote:Shame, good luck with that thoughvia _root.thats the way I'm gonna go.
If you have a better opinion I am all ears.
=D
At 12/2/09 10:10 AM, UndefinedArt wrote: If you have a better opinion I am all ears.
=D
They'll tell you to code on only the root frames only, or isolate everything into classes... ect... ect... which is actually a more organized way of doing it.
"Better" though, is relative to the person and the project.
If coding inside clips on those frames allows you to finish the game on time and under budget (Or just actually finish it) it's a better option.
If you can manage to separate everything into classes properly without getting bogged down with syntax and scope errors, than that's a better option.
Perpetually looking for time to return to the arts.
Well I shall look into all these things. Ty Johnny.