Exemple #1
0
        /// <summary>
        /// Retrusn the world affine transform matrix. The matrix is in Pixels.
        /// @since v0.7.1
        /// </summary>
        public CCAffineTransform nodeToWorldTransform()
        {
            CCAffineTransform t = this.nodeToParentTransform();

            CCNode p = m_pParent;

            while (p != null)
            {
                var temp = p.nodeToParentTransform();
                t = CCAffineTransform.CCAffineTransformConcat(t, temp);
                p = p.parent;
            }

            return(t);
        }
Exemple #2
0
        /// <summary>
        /// Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
        /// The matrix is in Pixels.
        /// @since v0.7.1
        /// </summary>
        public CCAffineTransform nodeToParentTransform()
        {
            if (m_bIsTransformDirty)
            {
                m_tTransform = CCAffineTransform.CCAffineTransformMakeIdentity();

                if (!m_bIsRelativeAnchorPoint && !m_tAnchorPointInPixels.IsZero)
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformTranslate(m_tTransform, m_tAnchorPointInPixels.x, m_tAnchorPointInPixels.y);
                }

                if (!m_tPositionInPixels.IsZero)
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformTranslate(m_tTransform, m_tPositionInPixels.x, m_tPositionInPixels.y);
                }

                if (m_fRotation != 0f)
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformRotate(m_tTransform, -ccMacros.CC_DEGREES_TO_RADIANS(m_fRotation));
                }

                if (m_fSkewX != 0f || m_fSkewY != 0f)
                {
                    // create a skewed coordinate system
                    CCAffineTransform skew = CCAffineTransform.CCAffineTransformMake(1.0f,
                                                                                     (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(m_fSkewY)),
                                                                                     (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f, 0.0f, 0.0f);
                    // apply the skew to the transform
                    m_tTransform = CCAffineTransform.CCAffineTransformConcat(skew, m_tTransform);
                }

                if (!(m_fScaleX == 1f && m_fScaleY == 1f))
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformScale(m_tTransform, m_fScaleX, m_fScaleY);
                }

                if (!m_tAnchorPointInPixels.IsZero)
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y);
                }

                m_bIsTransformDirty = false;
            }

            return(m_tTransform);
        }