问题
I was looking to see if someone can help me figure out how to create a panning effect over an already playing video in Flash AS3, where the camera is directed by where the mouse is.
For example, this game here http://www.kongregate.com/games/jorjeade/seven-deadly-sins (skip the intro to get to it quickly) has an over world map which pans around by using the mouse. I'm trying to achieve a similar effect for my flash video.
Any help coding this would be awesome! I'm also looking to see if I can get a basic zoom function working alongside this panning, also something that the user can control though the keyboard or similar.
I appreciate any help! Thanks.
回答1:
For my code to work as it is, set your movie clip anchor point to "centered."
myMovieClip.y = stage.stageHeight / 2;
addEventListener(MouseEvent.MOUSE_MOVE, panFunction);
private function panFunction(me:MouseEvent):void {
myMovieClip.x = stage.stageWidth/2 - (stage.mouseX - stage.stageWidth/2);
}
This will give a 1 to 1 motion that updates immediately with the mouse. You can throw in some multipliers or easing effect if you want, but hopefully this gets you going the right direction.
来源:https://stackoverflow.com/questions/37239283/flash-as3-pan-zoom-with-mouse-input