游戏中的镜头。锁定对象,根据计算坐标,修改父容器坐标,让物品处于最中点。
package { import flash.display.Sprite; import flash.display.Stage; import flash.events.Event; import flash.filters.GlowFilter; import flash.geom.Point; /** * @author:Gaara * 2012-3-16 * **/ public class Camer extends Sprite { private var myStage:Stage; private var target:Sprite; public function Camer(stage:Stage) { addChild(ResConfig.myLpBmp); this.myStage = stage; this.addEventListener(Event.ENTER_FRAME,onEnterFrame); } /** * 功能: * 参数: **/ public function lockAt(target:Sprite):void { if(this.target != null){ this.target.filters = []; } this.target = target; target.filters = [new GlowFilter(0x00FF00)]; } protected function onEnterFrame(event:Event):void { if(this.target != null){ var spriteCP:Point = globalToLocal(new Point(stage.stageWidth/2,stage.stageHeight/2)); var decX:Number = target.x - spriteCP.x; var decY:Number = target.y - spriteCP.y ; x -= decX; y -= decY; } } } }