的Flex /动作 - 雪碧旋转围绕其中心 [英] Flex/ActionScript - rotate Sprite around its center

查看:220
本文介绍了的Flex /动作 - 雪碧旋转围绕其中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个雪碧在ActionScript和渲染到一个Flex的画布。假设:

I have created a Sprite in Actionscript and rendered it to a Flex Canvas. Suppose:

var fooShape:Sprite = new FooSpriteSubclass();

fooCanvas.rawChildren.addChild(myshape);

//Sprite shape renders on screen

fooShape.rotation = fooNumber;

这将转动我的外形,但似乎其围绕左上角 点其父容器(画布)的。

This will rotate my shape, but seems to rotate it around the upper-left point of its parent container(the canvas).

我怎样才能迫使雪碧转动的是自己的心呢?我能明显 写code来计算的旋转,然后我们会重新渲染,但我认为 必须有一个内置的方式做到这一点,当然不希望推倒重来 如果可能的话。

How can I force the Sprite to rotate about is own center point? I could obviously write code to calculate the rotation, and then have it re-render, but I think there must be a built-in way to do this, and certainly do not want to 'reinvent the wheel' if possible.

我使用弹性,因此不必访问完整的Flash API。

I am using FlexBuilder, and therefore do not have access to the full Flash API.

感谢您了!

推荐答案

需要执行以下步骤基于一个参考点旋转对象(使用的矩阵对象的getBounds):

The following steps are required to rotate objects based on a reference point (using Matrix object and getBounds):

  1. 在矩阵转换(移动到参考点)
  2. 矩阵旋转
  3. 在矩阵转换(回到原始位置)


例如,要旋转一个物体围绕中心90度:


For example to rotate an object 90 degrees around its center:

// 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)); 



主要采用的方法:



Key methods used:

  • <一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Matrix.html#rotate%28%29"相对=nofollow> Matrix.rotate
  • <一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Matrix.html#translate%28%29"相对=nofollow> Matrix.translate
  • <一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#getBounds%28%29"相对=nofollow> DisplayObject.getBounds
  • Matrix.rotate
  • Matrix.translate
  • DisplayObject.getBounds

这篇关于的Flex /动作 - 雪碧旋转围绕其中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆