Flex/ActionScript - поверните Sprite вокруг его центра

По крайней мере, вы можете использовать debug_backtrace и проанализировать его, чтобы найти вызывающий метод.

Я думаю, что вы также должны быть в состоянии сделать это с помощью API отражения , но прошло слишком много времени с тех пор, как я использовал PHP, и я точно не помню, как именно. Однако ссылки должны, по крайней мере, помочь вам начать.

14
задан Ronnie Liew 25 November 2009 в 16:27
поделиться

2 ответа

Если вы хотите повернуть объект вокруг центра, просто отцентрируйте ресурс внутри вашего спрайта, установив параметр внутренние активы x и y равны половине ширины и высоты актива. Это позволит центрировать ваш контент и позволить ему вращаться вокруг центральной точки.

Пример загруженных ресурсов во время выполнения выглядит следующим образом:

var loader:Loader = new Loader():
var request:URLRequest = new URLRequest(path/to/asset.ext);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onLoaderComplete);
loader.load(request);

private function _onLoaderComplete(e:Event):void
{
    var mc:MovieClip = e.target.content as MovieClip;
    mc.x = -mc.width * 0.5;
    mc.y = -mc.height * 0.5;
    mc.rotation = 90;
    addChild(mc);
}
-1
ответ дан 1 December 2019 в 14:33
поделиться

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

  1. Matrix translation (moving to the reference point)
  2. Matrix rotation
  3. Matrix translation (back to original position)


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:

11
ответ дан 1 December 2019 в 14:33
поделиться
Другие вопросы по тегам:

Похожие вопросы: