0
我是一个flash actionscript3的初学者,我正在寻找一个动作脚本的小时,可以让我旋转动画片段的中心像任何图像经典旋转的角落,边框出现,和没有价值,只有手动旋转,我可以得到任何帮助吗?控制旋转边框闪光灯AC3
我是一个flash actionscript3的初学者,我正在寻找一个动作脚本的小时,可以让我旋转动画片段的中心像任何图像经典旋转的角落,边框出现,和没有价值,只有手动旋转,我可以得到任何帮助吗?控制旋转边框闪光灯AC3
我为你写了一些代码,如果我明白你想要的东西正确。将此代码放在第1帧上。对于要旋转的任何图片,请给它一个实例名称并致电makeRotatable(instanceNameOfYourPictureHere)
。
这不是完美的,但它是让你开始的东西。
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.geom.Rectangle;
//change "myPicture" to any object you want to make rotatable
makeRotatable(myPicture);
var currentObject:Object; //holds a reference to whichever objectis currently being rotated
var oldx:Number;//used to determine mouse movement on every new frame
var oldy:Number;
var boundsRect:Rectangle;//used for creating bounding box
function makeRotatable(target:DisplayObject){//this function sets up the rotation center and adds mouse handling
//creating a container for your picture
var pictureContainer:MovieClip = new MovieClip;
//adding it to the stage
stage.addChild(pictureContainer);
//setting its top left corner, around wich it will rotate, in the center of your picture
pictureContainer.x = target.x + target.width * 0.5;
pictureContainer.y = target.y + target.height * 0.5;
//adding your picture into the container, and moving its center onto the rotational point of the container
pictureContainer.addChild(target);
target.x = 0 - target.width * 0.5
target.y = 0 - target.height * 0.5
//adding mouse listeners to the container and stage
pictureContainer.addEventListener(MouseEvent.MOUSE_DOWN, startRotate)
stage.addEventListener(MouseEvent.MOUSE_UP, stopRotate)
}
function startRotate(e:MouseEvent):void{//sets up for EnterFrame listener and bounding box
stage.addEventListener(Event.ENTER_FRAME, changeRotation)
oldx = stage.mouseX
oldy = stage.mouseY
currentObject = e.currentTarget
boundsRect = currentObject.getBounds(currentObject)
currentObject.graphics.lineStyle(4,0xFF0000);
currentObject.graphics.drawRect(boundsRect.x, boundsRect.y, boundsRect.width, boundsRect.height);
}
function stopRotate(e:MouseEvent):void{//removes EnterFrame listener and bounding box
stage.removeEventListener(Event.ENTER_FRAME, changeRotation)
currentObject.graphics.clear();
}
function changeRotation(e:Event){//rotates the object based on mouse position and movement respective to objects center point
if(stage.mouseX>currentObject.x){
currentObject.rotation += stage.mouseY - oldy
}else{
currentObject.rotation -= stage.mouseY - oldy
}
if(stage.mouseY<currentObject.y){
currentObject.rotation += stage.mouseX - oldx
}else{
currentObject.rotation -= stage.mouseX - oldx
}
oldx = stage.mouseX
oldy = stage.mouseY
}
哇,这太神奇了,它的工作,非常感谢你:) Scab – Sam 2014-11-13 08:49:08