View Full Version : Help with DuplicateMC - shooting.
Philter123
10-30-2007, 03:39 AM
Hi,
i have been trying for hours to get my shoot function to work correctly. At the moment when i hit space bar my bullet fires, but when i hit space again, the previous bullet is removed and a new one is created. here is my script
function playershoots(){
x = Player._x;
y = Player._y;
if(Key.isDown(Key.SPACE)){
Player.gotoAndPlay("shoot");
attachMovie("bullet", "bullet", 11111111);
bullet._x = x-67;
bullet._y = y+10;
}
I have tried many things but i can't seem to get this working, i would just like to be able to press space and create as many bullets as space is pressed without deleting the previous one. I am pretty new to actionscript, but thanks for any help =)
Antonos
10-30-2007, 09:35 AM
you are using same depth 11111111, that is why MovieClip bullet overwrite last attached bullet every time
try to create some index
i++;
attachMovie("bullet", "bullet"+i, i);
Philter123
10-30-2007, 11:01 AM
i changed the original script to the one you suggested
"
i++;
attachMovie("bullet", "bullet"+i, i);
"
Still no luck, this time no bullets at all are being fired =(
Philter123
10-30-2007, 11:39 AM
ok here is the attachment... (finally:o )
Antonos
10-30-2007, 11:53 AM
I've attached changes fla, I added onEnterFrame to bullet
main concepts is wrong
you have to move bullets in each bullet, do not do it from root
and delete bullet when it goes out of screen
Philter123
10-30-2007, 12:34 PM
Oh, thanks a lot! you got it working
When space is pressed, a pig that is on screen is destoryed and the hittest doesnt work anymore, what do i have to change further down the script to work with the changed script, if anything?
Antonos
10-30-2007, 12:48 PM
add this code to onEnterFrame function
for (var i=_root.firstPig;i<=_root.lastPig;i++){
if (this.hitTest(_root["Pig"+i])){
_root.attachMovie("Pigsdead","Pigsdead",_root.getNextHighestDepth());
_root.Pigsdead.gotoAndPlay(1);
_root["Pig"+i].removeMovieClip();
attachMovie("PigDeath","PigDeath",99999999);
PigDeath._x = this._x;
PigDeath._y = this._y;
}
But I think better to rewrite complete game, because it was created it a bad way
Philter123
10-30-2007, 12:55 PM
I can't really rewrite the whole game as this is for my year 12 assignment and i can only really use script which i have been taught, i went the entire game so far without getting scripts off the net but i struggled on this. Also i dont know how to write the game in any other way, this is just the way we have been taught so i have to deal with it =(
Philter123
10-30-2007, 01:20 PM
Oh and thanks a lot for the help, i have fixed up most of the things i wanted to because of your help! One last thing, how would i remove the duplicated moveclip after it has hit a target?
Antonos
10-30-2007, 03:09 PM
for removing bullets change code
if(this._x<-10) {
this.removeMovieClip();
return;
}
this._x -= 10;
for (var i=_root.firstPig;i<=_root.lastPig;i++){
if (this.hitTest(_root["Pig"+i])){
this.removeMovieClip();
_root.attachMovie("Pigsdead","Pigsdead",_root.getNextHighestDepth());
_root.Pigsdead.gotoAndPlay(1);
_root["Pig"+i].removeMovieClip();
attachMovie("PigDeath","PigDeath",_root.getNextHighestDepth());
PigDeath._x = this._x;
PigDeath._y = this._y;
}
to delete all duplicated pigs on the end you have to create empty movie clip and through it on stage on the first frame
and you have to attach pigs in this movie clip
some_mc.attachMovie("Pig", "Pig"+lastPig, lastPig);
when game is over you are going to frame 2 and some_mc will delete automatically including pigs
hope this will help you
regards
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.