import flash.events.Event; import flash.geom.Rectangle; stage.addEventListener(Event.ENTER_FRAME, cameraFollowCharacter); function cameraFollowCharacter(evt:Event){ root.scrollRect = new Rectangle(char.x - stage.stageWidth/2, char.y - stage.stageHeight/2, stage.stageWidth, stage.stageHeight); }As you can see from the code, you will also need a movie clip on-stage called "char" (or if it is called something else, change the bits that say "char" in the code. This is an incredibly simple camera but very effective as it completely removed the lag from my game! I have also attached an example .fla so you can see how it all works (saved in Flash CS4): Source file: Joe Willmott's ActionScript 3.0 Camera
read more: Joe Willmott's Blog: Flash AS3 camera to follow your character
No comments:
Post a Comment