Monday, December 28, 2009

Can someone give me an actionscript 2.0 code that makes one movieclip follow another?

I'm making a game in Flash and I need a code that makes the camera follow my player. I know there's a code for the above question, but I don't know it.... Make sure it's ActionScript 2.0, not JavaScript or ActionScript 3.0 or 1.0 or whatever!Can someone give me an actionscript 2.0 code that makes one movieclip follow another?
Let's suppose your two movieclips are called mc1 and mc2:





//On the main timeline


onEnterFrame=function(){


mc2._x = mc1._x


mc2._y = mc1._y


}





//Alternatively, on mc1


onClipEvent(enterFrame){


mc2._x = _x


mc2._y = _y


}








Either of these should work. This of course will make one mc have the same position as the other mc. I'm not sure if that was what you meant, or maybe it was to follow it, as in being behind it?


Also, if you meant the camera to follow the player... then it wouldn't be a movie clip following another, but the player being static and the rest (the backround) moving, giving the illusion of a camera following the player.Can someone give me an actionscript 2.0 code that makes one movieclip follow another?
no problem, glad to help. Hey, email me the link to the game when you release it! Report Abuse

although that code well only make it stay ontop of it. here is a quick code i wrote up for movieclip1 and movieclip2 but this code goes on the main frame not inside of a symbol, it will make movieclip2 animate twords movieclip1 with a real nice effect, please give it a try :) Report Abuse

speed = 2;


_root.onEnterFrame = function() {


radian = (-1*(Math.atan2(_root.moviecli鈥?_root.movieclip1._x-movieclip2鈥?br>

degree = (-1*(Math.round((radian*180/Ma鈥?br>

movieclip2._rotation = degree;


_root.yvalue = Math.round(_root.movieclip1._y鈥? Report Abuse

._y);


_root.xvalue = Math.round(_root.movieclip1._x鈥?br>

_root.yvalue2 = Math.round(_root.yvalue);


_root.xvalue2 = Math.round(_root.xvalue);


movieclip2._y += _root.yvalue2/15;


movieclip2._x += _root.xvalue2/15;


} Report Abuse

i had to split the code into 2 because your not allowed to post too many characters in a comment Report Abuse

Check this out





Click on the Flash Tutorial and/or Flash Video Tutorial





http://forum.mytemplatebox.com/viewforum.php?f=38

No comments:

Post a Comment