I am using the action script below to rotate my cube.

I how ever have the problem of it rotating from the wrong center point even though I have set it to the middle.

I am aware that this can be done using action script just wondering about the syntax or any simple suggestions.

function cubeRotate(e:Event){
    mycube3d.rotationY = mycube3d.rotationY+1;
    mycube3d.rotationX = mycube3d.rotationX+1;

}
stage.addEventListener(Event.ENTER_FRAME,cubeRotate);
有帮助吗?

解决方案 2

setRegPoint(book, book.width / 2, book.height / 2);

function setRegPoint(obj:DisplayObjectContainer, newX:Number, NewY:Number):void {

    var bounds:Rectangle = obj.getBounds(obj.parent);
    var currentRegZ:Number = obj.z - bounds.top;

    var zOffset:Number = -50 - currentRegZ;

    obj.z += zOffset;

    for(var i:int = 0; i < obj.numChildren; i++) {
        obj.getChildAt(i).z -= zOffset;
    }
}

function cubeRotate(e:Event){    
  book.rotationY = book.rotationY+1    
  book.rotationX = book.rotationX+1    
}

stage.addEventListener(Event.ENTER_FRAME,cubeRotate)

其他提示

If you try to change "center point" in Flash IDE by dragging white circle - try to enclose "mycube3d" (or its content) to another movie and move it inside to set needed center

Because .rotationY will rotate your object around its zero coordinates and ignore ide's center setup.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top