1 Reply Latest reply on May 10, 2013 3:30 PM by prodigalmaster

    Vcam in AS2, help!


      I need help making a vcam that follows the character in AS2. The vcams that I tried are all way too laggy so i'd love any other alternatives. This seems to be a good one, but it's in AS3, if anyone could help me out with converting it to AS2 or even finding alternatives I would be forever in your debt! Thanks!


      Here's the AS3 code


      import flash.events.Event;

      import flash.geom.Rectangle;

      stage.addEventListener(Event.ENTER_FRAME, cameraFollowCharacter);

      function cameraFollowCharacter(event:Event){

      root.scrollRect = new Rectangle(_root.main.x - stage.stageWidth/2, _root.main.y - stage.stageHeight/2, stage.stageWidth, stage.stageHeight);


        • 1. Re: Vcam in AS2, help!
          prodigalmaster Level 2

          I am sure the reason the above code is laggy is because a new rectangle object is being made each frame. That is very inefficient. If you were to use objects, it could make more sense to create the object outside of the function and then just change the x/y positions and width/height of the rectangle object (I don't see the need to update the width/height if you are just making it follow the player unless it zooms in and out.


          As for code in AS2:


          Give the VCAM an identifier name by clicking the movieclip and going into it's properties. For example 'mcVcam'. Once you have done this, on each frame set the x and y position of the vcam to the player's:


          onEnterFrame = function(){

          mcVcam._x = player._x;

          //seeing your AS3 code it seems your player is called 'main', so you may wish to use that instead of 'player'.

          mcVcam._y = player._y;



          edit: oh and the code goes on the main timeline