首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >控制旋转与包围盒闪存AC3

控制旋转与包围盒闪存AC3
EN

Stack Overflow用户
提问于 2014-11-09 02:14:46
回答 1查看 200关注 0票数 0

我是一个闪光灯actionscript3的初学者,我一直在寻找一个动作脚本,可以让我在它的中心旋转电影,就像任何图像的经典旋转一样,出现了包围框,没有值,只有手动旋转,我能得到任何帮助吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-09 20:16:02

我给你写了一些代码,如果我正确理解了你想要的。将此代码放在框架1上。对于任何想要旋转的图片,请给它一个实例名并调用makeRotatable(instanceNameOfYourPictureHere)

这并不完美,但这是让你开始的事情。

代码语言:javascript
复制
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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26824252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档