BBGamelib.CCNode.updateTransform C# (CSharp) Method

updateTransform() public method

public updateTransform ( ) : void
return void
		public virtual void updateTransform(){
			if (_isUpdateTransformDirty) {
				//position

//				CGAffineTransform tmpAffine = nodeToParentTransform();
//				Vector2 pInParent = CGAffineTransform.CGPointApplyAffineTransform(_anchorPointInPixels, tmpAffine);
//				Vector2 pInUIUnits = ccUtils.PixelsToUnits (pInParent);
//				transform.localPosition = new Vector3 (pInUIUnits.x, pInUIUnits.y, transform.localPosition.z);

//				if(_parent!=null && _parent.ignoreAnchorPointForPosition){
//					CGAffineTransform tmpAffine = _parent.nodeToWorldTransform ();
//					Vector2 pInWorld = CGAffineTransform.CGPointApplyAffineTransform (_position, tmpAffine);
//					Vector2 pInUI = CCDirector.sharedDirector.convertToUI (pInWorld);
//					Vector2 pInUIUnits = ccUtils.PixelsToUnits (pInUI);
//
//					transform.position = new Vector3 (pInUIUnits.x, pInUIUnits.y, 0);
//
//					Vector3 localPos = transform.localPosition;
//					localPos.z = -_positionZ / UIWindow.PIXEL_PER_UNIT;
//					transform.localPosition = localPos;
//				}else{
//					Vector2 pInParentAR = _position;
//					if(_parent==null)
//						pInParentAR = CCDirector.sharedDirector.convertToUI(pInParentAR);
//					else
//						pInParentAR -= _parent._anchorPointInPixels;
//					Vector2 pInUIUnits = ccUtils.PixelsToUnits (pInParentAR);
//					Vector3 pos = transform.localPosition;
//					pos.x = pInUIUnits.x;
//					pos.y = pInUIUnits.y;
//					pos.z = -_positionZ / UIWindow.PIXEL_PER_UNIT;
//					transform.localPosition = pos;
//				}

				Vector2 pInParentAR = _position;
				if(_parent!=null && !_parent.ignoreAnchorPointForPosition){
					pInParentAR -= _parent._anchorPointInPixels;
				}
				Vector2 pInUIUnits = ccUtils.PixelsToUnits (pInParentAR);
				Vector3 pos = transform.localPosition;
				pos.x = pInUIUnits.x;
				pos.y = pInUIUnits.y;
				pos.z = 0;
				transform.localPosition = pos;

				
				//rotation
				Vector3 rotation = transform.localEulerAngles;
				rotation.x = 0;
				rotation.z = -_rotation;
				rotation.y = 0;
				bool negativeScaleX = FloatUtils.Small(_scaleX, 0);
				bool negativeScaleY = FloatUtils.Small(_scaleY, 0);
				if(negativeScaleX && negativeScaleY){
					rotation.z = 180 - _rotation;
				}else if(negativeScaleX){
					rotation.y = 180;
					rotation.z = _rotation;
				}else if(negativeScaleY){
					rotation.y = 180;
					rotation.z = _rotation + 180;
				}

				transform.localEulerAngles = rotation;
				
				//scale			
				transform.localScale = new Vector3 (Mathf.Abs (_scaleX), Mathf.Abs (_scaleY), transform.localScale.z);

				_isUpdateTransformDirty = false;
			}
		}
		#endregion

Usage Example

 // ------------------------------------------------------------------------------
 //  CCNode Transformations
 // ------------------------------------------------------------------------------
 protected virtual void transformAncestors()
 {
     if (_parent != null)
     {
         _parent.transformAncestors();
         _parent.updateTransform();
     }
 }