public override void Visit() { CCPoint pos = AbsolutePosition(); if (!pos.Equals(m_tLastPosition)) { for (int i = 0; i < m_pParallaxArray.Count; i++) { var point = m_pParallaxArray[i]; float x = -pos.X + pos.X * point.Ratio.X + point.Offset.X; float y = -pos.Y + pos.Y * point.Ratio.Y + point.Offset.Y; point.Child.Position = new CCPoint(x, y); } m_tLastPosition = pos; } base.Visit(); }
private CCPoint CalculateLayerOffset(CCPoint pos) { CCPoint ret = CCPoint.Zero; switch (m_uLayerOrientation) { case CCTMXOrientation.Ortho: ret = new CCPoint(pos.X * m_tMapTileSize.Width, -pos.Y * m_tMapTileSize.Height); break; case CCTMXOrientation.Iso: ret = new CCPoint((m_tMapTileSize.Width / 2) * (pos.X - pos.Y), (m_tMapTileSize.Height / 2) * (-pos.X - pos.Y)); break; case CCTMXOrientation.Hex: Debug.Assert(pos.Equals(CCPoint.Zero), "offset for hexagonal map not implemented yet"); break; } return(ret); }
private CCPoint CalculateLayerOffset(CCPoint pos) { CCPoint ret = CCPoint.Zero; switch (m_uLayerOrientation) { case CCTMXOrientation.Ortho: ret = new CCPoint(pos.X * m_tMapTileSize.Width, -pos.Y * m_tMapTileSize.Height); break; case CCTMXOrientation.Iso: ret = new CCPoint((m_tMapTileSize.Width / 2) * (pos.X - pos.Y), (m_tMapTileSize.Height / 2) * (-pos.X - pos.Y)); break; case CCTMXOrientation.Hex: Debug.Assert(pos.Equals(CCPoint.Zero), "offset for hexagonal map not implemented yet"); break; } return ret; }
public virtual CCAffineTransform NodeToParentTransform() { if (m_bTransformDirty) { // Translate values float x = m_obPosition.X; float y = m_obPosition.Y; if (m_bIgnoreAnchorPointForPosition) { x += m_obAnchorPointInPoints.X; y += m_obAnchorPointInPoints.Y; } // Rotation values // Change rotation code to handle X and Y // If we skew with the exact same value for both x and y then we're simply just rotating float cx = 1, sx = 0, cy = 1, sy = 0; if (m_fRotationX != 0 || m_fRotationY != 0) { float radiansX = -CCMacros.CCDegreesToRadians(m_fRotationX); float radiansY = -CCMacros.CCDegreesToRadians(m_fRotationY); cx = (float)Math.Cos(radiansX); sx = (float)Math.Sin(radiansX); cy = (float)Math.Cos(radiansY); sy = (float)Math.Sin(radiansY); } bool needsSkewMatrix = (m_fSkewX != 0f || m_fSkewY != 0f); // optimization: // inline anchor point calculation if skew is not needed if (!needsSkewMatrix && !m_obAnchorPointInPoints.Equals(CCPoint.Zero)) { x += cy * -m_obAnchorPointInPoints.X * m_fScaleX + -sx * -m_obAnchorPointInPoints.Y * m_fScaleY; y += sy * -m_obAnchorPointInPoints.X * m_fScaleX + cx * -m_obAnchorPointInPoints.Y * m_fScaleY; } // Build Transform Matrix // Adjusted transform calculation for rotational skew m_sTransform.a = cy * m_fScaleX; m_sTransform.b = sy * m_fScaleX; m_sTransform.c = -sx * m_fScaleY; m_sTransform.d = cx * m_fScaleY; m_sTransform.tx = x; m_sTransform.ty = y; // XXX: Try to inline skew // If skew is needed, apply skew and then anchor point if (needsSkewMatrix) { var skewMatrix = new CCAffineTransform( 1.0f, (float)Math.Tan(CCMacros.CCDegreesToRadians(m_fSkewY)), (float)Math.Tan(CCMacros.CCDegreesToRadians(m_fSkewX)), 1.0f, 0.0f, 0.0f); m_sTransform = CCAffineTransform.Concat(skewMatrix, m_sTransform); // adjust anchor point if (!m_obAnchorPointInPoints.Equals(CCPoint.Zero)) { m_sTransform = CCAffineTransform.Translate(m_sTransform, -m_obAnchorPointInPoints.X, -m_obAnchorPointInPoints.Y); } } if (m_bAdditionalTransformDirty) { m_sTransform.Concat(ref m_sAdditionalTransform); m_bAdditionalTransformDirty = false; } m_bTransformDirty = false; } return(m_sTransform); }
public virtual CCAffineTransform NodeToParentTransform() { if (m_bIsTransformDirty) { // Translate values float x = m_tPosition.X; float y = m_tPosition.Y; if (m_bIgnoreAnchorPointForPosition) { x += m_tAnchorPointInPoints.X; y += m_tAnchorPointInPoints.Y; } // Rotation values float c = 1, s = 0; if (m_fRotation != 0.0f) { float radians = -CCMacros.CCDegreesToRadians(m_fRotation); c = (float)Math.Cos(radians); s = (float)Math.Sin(radians); } bool needsSkewMatrix = (m_fSkewX != 0f || m_fSkewY != 0f); // optimization: // inline anchor point calculation if skew is not needed if (!needsSkewMatrix && !m_tAnchorPointInPoints.Equals(CCPoint.Zero)) { x += c * -m_tAnchorPointInPoints.X * m_fScaleX + -s * -m_tAnchorPointInPoints.Y * m_fScaleY; y += s * -m_tAnchorPointInPoints.X * m_fScaleX + c * -m_tAnchorPointInPoints.Y * m_fScaleY; } // Build Transform Matrix //m_tTransform = new CCAffineTransform( // c * m_fScaleX, s * m_fScaleX, // -s * m_fScaleY, c * m_fScaleY, // x, y); // Build Transform Matrix m_tTransform.a = c * m_fScaleX; m_tTransform.b = s * m_fScaleX; m_tTransform.c = -s * m_fScaleY; m_tTransform.d = c * m_fScaleY; m_tTransform.tx = x; m_tTransform.ty = y; // XXX: Try to inline skew // If skew is needed, apply skew and then anchor point if (needsSkewMatrix) { var skewMatrix = new CCAffineTransform( 1.0f, (float)Math.Tan(CCMacros.CCDegreesToRadians(m_fSkewY)), (float)Math.Tan(CCMacros.CCDegreesToRadians(m_fSkewX)), 1.0f, 0.0f, 0.0f); m_tTransform = CCAffineTransform.Concat(skewMatrix, m_tTransform); // adjust anchor point if (!m_tAnchorPointInPoints.Equals(CCPoint.Zero)) { m_tTransform = CCAffineTransform.Translate(m_tTransform, -m_tAnchorPointInPoints.X, -m_tAnchorPointInPoints.Y); } } m_bIsTransformDirty = false; } return(m_tTransform); }
public bool Equals(CCRect rect) { return(Origin.Equals(rect.Origin) && Size.Equals(rect.Size)); }