Forum Topic: duplicating movie clips help

(120 views • 4 replies)

This topic is 1 page long.

<< < > >>
None

mercygames

Reply To Post Reply & Quote

Posted at: 1/2/08 10:42 PM

mercygames NEUTRAL LEVEL 07

Sign-Up: 11/23/03

Posts: 156

i run this script on frame 1:

onLoad = function () {
for (i=1; i<_root.stats.level*5; i++){
duplicateMovieClip(_root.enemy, "MC"+i, 1000+i);
_root["MC"+i]._x = random(600)+550;
_root["MC"+i]._y = random(600)-150;}
}

it makes a random amount of enemies positioned off screen to the right. the enemy (the mc that is being duplicated) has this script for when the frame is 3:

if(_root._currentframe == 3){
this.removeMovieClip();
}
they also die when a bullet hits them.

MY PROBLEM::
one the player is on frame 3 he can choose to go back to frame 1, but when it goes back to frame 1, the only movie clip that appears on the stage is the enemy (no duplicates!)

anyone know why?? please help :(


None

Drkgodz

Reply To Post Reply & Quote

Posted at: 1/2/08 11:31 PM

Drkgodz DARK LEVEL 09

Sign-Up: 08/26/06

Posts: 30

Last time I checked, you can't duplicate more than 1 movie clip with that.
I.E
You can't duplicate mc1 more than once.
So to duplicate, what I do is, I give my movie clip a linkage identifier(via the library->right click->linkage) and load it from the library at run time and position it, etc.


None

mercygames

Reply To Post Reply & Quote

Posted at: 1/2/08 11:41 PM

mercygames NEUTRAL LEVEL 07

Sign-Up: 11/23/03

Posts: 156

alrite so how can i change the code that i have on the mc that is being duplicated? i would need to put it in the first frame of the enemy mc, right? here's the code:

onLoad = function(){
	spd=1;
}

onEnterFrame = function(){
	if(this.hitTest(_root.wall)){
			this.play();
		}
	if(this.hitTest(_root.wall_3)){
			this.play();
		}
	if(this.hitTest(_root.wall_4)){
		this.play();
	}
	_visible = true;
	Xdiff=_parent.player._x-_x;
	Ydiff=_parent.player._y-_y;
	radAngle=Math.atan2(Ydiff,Xdiff);
	_rotation=int((radAngle*360/(2*Math.PI))+90);
	if(_root._currentframe == 3){
		this.removeMovieClip();
	}
		if(this.hitTest(_parent.player)){
			//attack or something...
		}else{
			if(_rotation>180){
				_y+=(spd*Math.cos(Math.PI/180*_rotation));
				_x-=(spd*Math.sin(Math.PI/180*_rotation));
			}else{
				_y-=(spd*Math.cos(Math.PI/180*_rotation));
				_x+=(spd*Math.sin(Math.PI/180*_rotation));
			}
		}
	}

None

mercygames

Reply To Post Reply & Quote

Posted at: 1/3/08 12:13 AM

mercygames NEUTRAL LEVEL 07

Sign-Up: 11/23/03

Posts: 156

ok well I have the enemys moving and randomly spawning, but i still have my original problem even after using attachMovie. here's my code on frame 1:

stop();

onEnterFrame = function () { 
for (i=1; i<((_root.stats.level*5)+1); i++){
	_root.attachMovie("enemy", "MC"+i, 1000+i);
	_root["MC"+i]._x = random(600)+550;
	_root["MC"+i]._y = random(600)-150;
	}
}

var bc=15;
var snd = new Sound();
snd.attachSound("9mm_snd");

_root.onMouseDown = function(){
	_root.snd.start(0,0);
	if(_root.stats.ammo<=1){
		_root.stats.ammo=0;
		gotoAndStop(2);
	}else{
		_root.stats.ammo--;
	}
		bc++;
		if(bc>30){
			bc=15;
	}
	duplicateMovieClip("bullet", "b"+bc, bc);
}

and heres the code on the first frame of the enemy mc that is not on the stage:

stop();
var spd = 1;

onLoad = function(){
	pmove();
}
pmove = function (){
	if(this.hitTest(_root.wall)){
			this.play();
		}
	if(this.hitTest(_root.wall_3)){
			this.play();
		}
	if(this.hitTest(_root.wall_4)){
			this.play();
		}
		_visible = true;
		Xdiff=_parent.player._x-_x;
		Ydiff=_parent.player._y-_y;
		radAngle=Math.atan2(Ydiff,Xdiff);
		_rotation=int((radAngle*360/(2*Math.PI))+90);
		if(_root._currentframe == 3){
			this.removeMovieClip();
		}
			if(this.hitTest(_parent.player)){
			//attack or something...
		}else{
			if(_rotation>180){
				_y+=(spd*Math.cos(Math.PI/180*_rotation));
				_x-=(spd*Math.sin(Math.PI/180*_rotation));
		}else{
			_y-=(spd*Math.cos(Math.PI/180*_rotation));
			_x+=(spd*Math.sin(Math.PI/180*_rotation));
		}
	}
}

None

Drkgodz

Reply To Post Reply & Quote

Posted at: 1/3/08 12:14 AM

Drkgodz DARK LEVEL 09

Sign-Up: 08/26/06

Posts: 30

At 1/2/08 11:41 PM, mercygames wrote: alrite so how can i change the code that i have on the mc that is being duplicated? i would need to put it in the first frame of the enemy mc, right? here's the code:

onLoad = function(){
spd=1;
}

onEnterFrame = function(){
if(this.hitTest(_root.wall)){
this.play();
}
if(this.hitTest(_root.wall_3)){
this.play();
}
if(this.hitTest(_root.wall_4)){
this.play();
}
_visible = true;
Xdiff=_parent.player._x-_x;
Ydiff=_parent.player._y-_y;
radAngle=Math.atan2(Ydiff,Xdiff);
_rotation=int((radAngle*360/(2*Math.PI))

+90);

if(_root._currentframe == 3){
this.removeMovieClip();
}
if(this.hitTest(_parent.player)){
//attack or something...
}else{
if(_rotation>180){
_y+=(spd*Math.cos(Math.PI/180*_rotation)

);

_x-=(spd*Math.sin(Math.PI/180*_rotation)

);

}else{
_y-=(spd*Math.cos(Math.PI/180*_rotation)

);

_x+=(spd*Math.sin(Math.PI/180*_rotation)

);

}
}
}

Ok:
var iD:Number = random(500);
_root.createEmptyMovieClip("enemy"+iD,_r oot.getNextHighestDepth());
_root["enemy"+iD].attachMovie("enemy", "enemy_mc", this.getNextHighestDepth());
_root["enemy"+iD].enemy_mc.onEnterFrame = function()
{
//actionscript here
//the action script will have to be edited to be on a frame instead of a movie clip
//dont ask me how
}
have your linkage ID be enemy.


All times are Eastern Standard Time (GMT -5) | Current Time: 08:39 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!