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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |