# Using Matrix3d to rotate Sprite around Center Point

**URL:** <https://forum.kirupa.com/t/using-matrix3d-to-rotate-sprite-around-center-point/299845>\
**Category:** flash\
**Created:** [November 11, 2009, 7:48pm UTC](https://forum.kirupa.com/t/using-matrix3d-to-rotate-sprite-around-center-point/299845 "2009-11-11T19:48:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thinker2501](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Thinker2501](https://forum.kirupa.com/u/Thinker2501)\
**Post date:** [November 11, 2009, 7:48pm UTC](https://forum.kirupa.com/t/using-matrix3d-to-rotate-sprite-around-center-point/299845/1 "2009-11-11T19:48:13Z")

</div>

I have a sprite that I want to rotate around it’s center point. Below is the custom class I wrote. For some reason the Sprite rotates around 0 point of the Y-axis instead of it’s own center point. If anyone could show me what I’m doing wrong it would be greatly appreciated.

```auto

package lib
{
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	public class CoverFlowObj extends Sprite
	{
		var _centerStageX:uint;
		var _centerStageY:uint;
		var _maxRotation:Number;
		var _rotationSpeed:Number;
		var _w:uint;
		var _h:uint;
		
		public function CoverFlowObj (w:uint, h:uint)
		{
			// set variables
			_maxRotation = 65;
			_rotationSpeed = .5;
			_w = w;
			_h = h;
			
			// wait until added to display stack;
			this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		// initialize;
		private function init (e:Event):void
		{
			_centerStageX = Math.floor (stage.stageWidth/2);
			_centerStageY = Math.floor (stage.stageHeight/2);
			
			var bg:Shape = drawRect(_w, _h);
			addChild(bg);
			
			init3d();
			
			this.addEventListener(Event.ENTER_FRAME, rotate);
		} //end init()
		
		// return rectangle Shape of specified width / height;
		private function drawRect (w:uint, h:uint):Shape
		{
			var rect:Shape = new Shape();
			rect.graphics.beginFill (0x666666);
			rect.graphics.drawRect (0, 0, w, h);
			rect.graphics.endFill();
			
			return rect;
		} //end drawRect()
		
		// set starting 3D coordinates;
		private function init3d ():void
		{			
			this.x = _centerStageX - this.width / 2;
			this.y = _centerStageY - this.height / 2;
			this.z = 1;
		}
		
		// rotate shape around y axis;
		private function rotate (e:Event):void
		{
			this.transform.matrix3D.appendRotation(_rotationSpeed, Vector3D.Y_AXIS);
		}
	} //end Class
} //end Package

```
