加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex / ActionScript – 围绕其中心旋转Sprite

发布时间:2020-12-15 02:15:17 所属栏目:百科 来源:网络整理
导读:我已经在Actionscript中创建了一个Sprite,并将其渲染到Flex Canvas.假设: var fooShape:Sprite = new FooSpriteSubclass();fooCanvas.rawChildren.addChild(myshape);//Sprite shape renders on screenfooShape.rotation = fooNumber; 这将旋转我的形状,但
我已经在Actionscript中创建了一个Sprite,并将其渲染到Flex Canvas.假设:
var fooShape:Sprite = new FooSpriteSubclass();

fooCanvas.rawChildren.addChild(myshape);

//Sprite shape renders on screen

fooShape.rotation = fooNumber;

这将旋转我的形状,但似乎围绕左上方旋转
它的父容器(画布)的点.

如何强制Sprite旋转自己的中心点?我显然可以
编写代码来计算旋转,然后重新渲染,但我认为
必须是一种内置的方式来做到这一点,当然不想“重塑轮子”
如果可能的话.

我使用FlexBuilder,因此无法访问完整的Flash API.

非常感谢

解决方法

基于参考点旋转对象需要以下步骤(使用 Matrix对象和getBounds):

矩阵翻译(移到参考点)
>矩阵旋转
矩阵翻译(回原位)

例如,将对象围绕其中心旋转90度:

// Get the matrix of the object  
var matrix:Matrix = myObject.transform.matrix; 

// Get the rect of the object (to know the dimension) 
var rect:Rectangle = myObject.getBounds(parentOfMyObject); 

// Translating the desired reference point (in this case,center)
matrix.translate(- (rect.left + (rect.width/2)),- (rect.top + (rect.height/2))); 

// Rotation (note: the parameter is in radian) 
matrix.rotate((90/180)*Math.PI); 

// Translating the object back to the original position.
matrix.translate(rect.left + (rect.width/2),rect.top + (rect.height/2));

使用的关键方法:

> Matrix.rotate
> Matrix.translate
> DisplayObject.getBounds

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读