Allright, heres the sich, I'm working on a space side scroller called "Exciting Fun X-Wing shooting Adventure!" Catchy huh? Anyway, the way it works is theres the menu, you choose your difficulty, then it goes to the game. But heres my conflict. Whenever you goto anouther scene, the Tie Fighters are still going across the screen. The TIEs are made with a "Duplicate" method in which its ment to keep them comming, my problem is that I'm trying to figure out how to get them to stop. If anyone can help I would be eternally greatful.
For some info, heres my code for all the key parts.
easiest way would be to get all the xwings to 'kill' themselves, so create a variable in the main timeline with your control bit, call it playing and set it to true, now when the ship collides with an xwing im guessing thats game over right? if so you should set the _root.playing=false. Then what you want is a piece of code in the xwing on enter frame, put an if statment saying that if _root.playing==false then this.removeMovieClip or whatever you are using to remove an enemy once it has collided with the ship, this will remove all of your enemies.
Then to stop them being created just put your chunk of code that is creating enemies inside an if statement that says if playing ==true.
You will probably need to place that code on a _root.onenterframe function in your main timeline.
Hopethat helps, if you cant do what ive said then post the flash and ill try and update it for you.
If our body is a clock ticking away and if while we experience all that this world has to offer time has still continued to pass, are we living or just experiencing a slow death?
I tried several things but none really seemed to work from my attempts (I'm very much a novice at flash so bare witn me, heh). So I'll just post the fla file. Note this is the file before adding any playing functions.
And just so you know... there are a few inside jokes in this game so, bare with xD.
I would highly recommend removing the enterFrame on every single TIE fighter MC. This is extremely inefficient and will cause extreme slowdown in the game when you decide to add more stuff to it. Instead, have each TIE fighter be put into an array, or a container clip.
Persoanlly, i use the array mehtod (for which reason i dont know).
First, you need to create a new array:
code:
_root.tieFighterArray = new Array();
Then, when you are creating a TIE fighter, add that instance into the array using the push method:
code:
_root.tieFighterArray.push(duplicated movie clip instance name);
Then, create a function that will scroll through this array:
PHP Code:
_root.tieFighterMove = function() {
//Optimize by making _root a var
var r = _root;
//use a while funtion to loop through the array. I prefer to loop from the last element, this gets rid of the hassle of sorting the elements when something is removed
var i = r.tieFighterArray.length-1;
//remember, the r stands for _root
while (i>=0) {
//this gets you the instance name of the duplicated tie fighter movie clip
var name = r.tieFighterArray[i];
//remember, the r stands for _root
//Moving code, collision code, and all other TIE fighter related codes go in here
i--;
}
}
All you need now is one movie clip that contains all the enterFrame commands. In that movie clip, call the function _root.tieFighterMove every frame by
code:
_root.tieFighterMove();
Now that you have the array and movement set up, all you need is a clean code that removes all the elements in the tie fighter array when you need.
PHP Code:
_root.clean = function() {
var r = _root;
var i = r.tieFighterArray.lenght-1;
while(i>=0) {
//this gets you the instance name of the duplicated tie fighter movie clip
var name = r.tieFighterArray[i];
//remember, the r stands for _root
//This removes the movie clip
name.removeMovieClip();
//This removes the element from the array
r.tieFighterArray.splice(name,1);
//The instance name (_root.tieFighterArray[i]) is removed from the array and onle 1 element is removed from that point
i--;
}
}
Now all you need to do is call the clean function by using
code:
_root.clean();
to remove all the tie fighters.
I hope this is not too confusing. I typed this code up from scratch, so i cant guarantee a bug free code, you might need to edit some syntax, but the basic idea is there. I would recommend changing some function and variable names to shorter stuff to optimize even more. Also, i would also recommend this approach with the bullets.
For more help, look up arrays and array functions in flash help.
Post here if you have any more questions, hope this helps =)
On another note, I dont think the actionscipt or php code thing is working properly. It's not inserting the tabs in the functions or loops automatically. Maybe its just because there is a syntax, or is anyone else noticing this. I had to space the lines myself.
Testing:
code:
if (variable>number) {
variable = number;
}
Last edited by dbarbarian; 06-01-2005 at 01:40 PM.
I get the basic idea of all the code, I'm just a bit unsure on where to put what. (Sorry I'm very much a, n00b when it comes to actionscript as this is my first real attempt at something like this)
Edit: Nevermind, i get what you're saying squize.
Still not sure what pkmnpeter is trying to say...
As to the code, the array codes, the functions, etc, all go on a frame. The moving function is called on a enter frame on a movie clip so it moves the tie fighter every frame.. The clean function is put wherever you want to clean the code.
Hope that helps.