duplicate function O.O

Subscribe to duplicate function O.O 23 posts, 5 voices

Sign in to reply


 
avatar for Rilliden Rilliden 370 posts
Flag Post

Im doing a tutorial and it says use the duplicate function and i dont know how to do that. Can someone please help me.
You’ll need to create a movieclip to be the bullet and give it that instance name. Make another movieclip (which could be a tank, cannon, protagonist, etc) with the instance name: player. The bullet movieclip should be placed at the center of the player with actionscript. We want the bullet to duplicate, so with actionscript 2 you could simply use the duplicateMovieClip function. Otherwise, if you use AS3, you may want to see another tutorial for that part. Make sure the original movieclip does not move (ex: _name can be used to distinguish it).

Next, place the aiming code on the player. With an onMouseDown function or something equivalent, the bullet should be set to duplicate. Then use the following code for the duplicated bullets (especially if you use as3, change it a bit if you need it to be on the timeline):

speed = 20; //This can be changed however you like.
xTarget = xmouse;
yTarget = _ymouse;
if(xChange==undefined){
//A proportion is found here between x and y coordinates
xChange = (xTarget/this.
x);
yChange = (yTarget/this._y);
}
//Using the proportion, we can make it move in a line.
//The proportion is multiplied by speed to make the bullet move quickly
_x+=xChange*speed;
_y+=yChange*speed;

I know that for some, this code may seem a bit weird, but it’s simple and it works. This isn’t the only way to do it either. The rest is up to you, but I hope this helps a bit.
Also wheres the error in this? xDifference = player._x – _xmouse; I cant find it.

 
avatar for Rilliden Rilliden 370 posts
Flag Post

also xDifference = player._x – _xmouse; is a syntax error.

 
avatar for Jabor Jabor 9716 posts
Flag Post

If you don’t know how to do something, you look up the documentation. It’s really easy to do and a lot faster than waiting for someone to tell you where the documentation is.

 
avatar for Rilliden Rilliden 370 posts
Flag Post

i know but im looking at that going O.O .

 
avatar for saybox saybox 140 posts
Flag Post

here’s a tutorial about duplicating clips that might explain better :)

http://www.actionscript.org/resources/articles/39/1/Using-duplicateMovieClip/Page1.html

 
avatar for Rilliden Rilliden 370 posts
Flag Post

thank you saybox but how would i make that appear on my character?

 
avatar for saybox saybox 140 posts
Flag Post

after you duplicate it, set it to the player coordinates :)

 
avatar for Rilliden Rilliden 370 posts
Flag Post

wait but how would i place that in script because my players moveing i have a guess but looking at it i know its wrong.

 
avatar for saybox saybox 140 posts
Flag Post

It only needs to start at the player’s location – it’s a bullet, so after that it’s gonna be movingby itself.

Post your guess and lets see where youn eed correcting. that’s better than soemnoe writing the whoel thing for you :)

 
avatar for Rilliden Rilliden 370 posts
Flag Post

argh im seriously guessing on this one

on (release) { _root.bullet.duplicatemovieclip("bullet") }
and i dont have a clue about how to make the bullet go to the player i know its x and y something like that i have seen it and am being driven insane.

 
avatar for Jabor Jabor 9716 posts
Flag Post

Have you actually looked up the documentation?

The parameters you need to pass in are:

1. The instance name of the new movieclip (so no, calling it the same as the old one is not going to work)
2. The depth to place the new movieclip at

 
avatar for Rilliden Rilliden 370 posts
Flag Post

O.O

 
avatar for saybox saybox 140 posts
Flag Post
Originally posted by Rilliden:

argh im seriously guessing on this one

on (release) { _root.bullet.duplicatemovieclip("bullet") }

and i dont have a clue about how to make the bullet go to the player i know its x and y something like that i have seen it and am being driven insane.

Well you’re close :)

_root.bullet.duplicateMovieClip("bullet" + counter,_root.getNextHighestDepth());
_root["bullet" + counter]._x = _root.player._x;
_root["bullet" + counter]._y = _root.player._y;
_root.counter   ++

you’re going to need a variable for counter, of course – this is so that each new bullet will have its own name. bullet1, bullet2, etc.

The getnexthighestdepth tells flash to find somewhere to put it :P

the rest is hopefulyl clear to what it does, but if you don’t understand then go ahead and ask and i’ll explain in more detail :)

 
avatar for Rilliden Rilliden 370 posts
Flag Post

also whats wrong with this i cant find it D:
xDifference = player.x – _xmouse;
yDifference = player.
y – _ymouse;
var angleRadians:Number = Math.atan2(yDifference, xDifference);
var angleDegrees:Number = Math.round(angleRadians
180/Math.PI);
player._rotation = angleDegrees;*

 
avatar for MainFrame_Games MainFrame_Games 192 posts
Flag Post

dx = player._x – _root._xmouse;
dy = player._y – _root._ymouse;
var angleRadians:Number = Math.atan2(dy, dx);
var angleDegrees:Number = (angleRadians*180/Math.PI);
player._rotation = angleDegrees;

Place in an onEnterFrame function on the main timeline.
Also why did you round angleDegrees? Their is no need for that.

 
avatar for Rilliden Rilliden 370 posts
Flag Post

saybox would i just put on(release) function infront of that?

 
avatar for saybox saybox 140 posts
Flag Post

second paragraph in your first post tells you what do there :)

 
avatar for Rilliden Rilliden 370 posts
Flag Post

lol kk

 
avatar for Rilliden Rilliden 370 posts
Flag Post

still got a syntax error on
xDifference = player.x – _xmouse;
yDifference = player.
y – _ymouse;

 
avatar for saybox saybox 140 posts
Flag Post

i think mainframe already corected that for you :p

 
avatar for Rilliden Rilliden 370 posts
Flag Post

nope that didnt change anything.

 
avatar for Rilliden Rilliden 370 posts
Flag Post

help D:

 
avatar for illegal illegal 51 posts
Flag Post

try

xDifference = player._x – _root._xmouse;
yDifference = player._y – _root._ymouse;

Sign in to reply


Click Here