Rilliden
370 posts
|
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.
|
|
|
Rilliden
370 posts
|
also xDifference = player._x – _xmouse; is a syntax error.
|
|
|
Jabor
9716 posts
|
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.
|
|
|
Rilliden
370 posts
|
i know but im looking at that going O.O .
|
|
|
saybox
140 posts
|
|
|
|
Rilliden
370 posts
|
thank you saybox but how would i make that appear on my character?
|
|
|
saybox
140 posts
|
after you duplicate it, set it to the player coordinates :)
|
|
|
Rilliden
370 posts
|
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.
|
|
|
saybox
140 posts
|
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 :)
|
|
|
Rilliden
370 posts
|
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.
|
|
|
Jabor
9716 posts
|
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
|
|
|
Rilliden
370 posts
|
|
|
|
saybox
140 posts
|
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 :)
|
|
|
Rilliden
370 posts
|
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(angleRadians180/Math.PI);
player._rotation = angleDegrees;*
|
|
|
MainFrame_Games
192 posts
|
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.
|
|
|
Rilliden
370 posts
|
saybox would i just put on(release) function infront of that?
|
|
|
saybox
140 posts
|
second paragraph in your first post tells you what do there :)
|
|
|
Rilliden
370 posts
|
|
|
|
Rilliden
370 posts
|
still got a syntax error on
xDifference = player.x – _xmouse;
yDifference = player.y – _ymouse;
|
|
|
saybox
140 posts
|
i think mainframe already corected that for you :p
|
|
|
Rilliden
370 posts
|
nope that didnt change anything.
|
|
|
Rilliden
370 posts
|
|
|
|
illegal
51 posts
|
try
xDifference = player._x – _root._xmouse;
yDifference = player._y – _root._ymouse;
|