Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Vcam in AS2, help!

Guest
May 08, 2013 May 08, 2013

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);

}

TOPICS
ActionScript
3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 10, 2013 May 10, 2013
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines