public void visit() { if (_body != null && scheduledForRemoval == true) { this.removeBody(); } if (_body != null) { CCAffineTransform trans = b2BodyToParentTransform(_node, this); CCPoint localPos = CCAffineTransform.Transform(_node.AnchorPointInPoints, trans); ((LHPhysicsProtocol)_node).updatePosition(localPos); ((LHPhysicsProtocol)_node).updateRotation(CCNodeTransforms.LocalXAngleFromGlobalAngle(_node, LHUtils.LH_RADIANS_TO_DEGREES(-_body.Angle))); } }
public override void Setup() { CCSprite target = new CCSprite(TestResource.s_pPathBlock); target.AnchorPoint = CCPoint.Zero; target.Scale = 3; m_pOuterClipper = new CCClippingNode(); CCAffineTransform tranform = CCAffineTransform.Identity; tranform = CCAffineTransform.ScaleCopy(tranform, target.ScaleX, target.ScaleY); m_pOuterClipper.ContentSize = CCAffineTransform.Transform(target.ContentSize, tranform); m_pOuterClipper.AnchorPoint = new CCPoint(0.5f, 0.5f); m_pOuterClipper.RunAction(new CCRepeatForever(new CCRotateBy(1, 45))); m_pOuterClipper.Stencil = target; CCClippingNode holesClipper = new CCClippingNode(); holesClipper.Inverted = true; holesClipper.AlphaThreshold = 0.05f; holesClipper.AddChild(target); m_pHoles = new CCNode(m_pOuterClipper.ContentSize); holesClipper.AddChild(m_pHoles); m_pHolesStencil = new CCNode(m_pOuterClipper.ContentSize); holesClipper.Stencil = m_pHolesStencil; m_pOuterClipper.AddChild(holesClipper); this.AddChild(m_pOuterClipper); var listener = new CCEventListenerTouchAllAtOnce(); listener.OnTouchesBegan = onTouchesBegan; AddEventListener(listener); }
public override void Setup() { CCSprite target = new CCSprite(TestResource.s_pPathBlock); target.AnchorPoint = CCPoint.Zero; target.Scale = 3; m_pOuterClipper = new CCClippingNode(); CCAffineTransform tranform = CCAffineTransform.Identity; tranform = CCAffineTransform.Scale(tranform, target.Scale, target.Scale); m_pOuterClipper.ContentSize = CCAffineTransform.Transform(target.ContentSize, tranform); m_pOuterClipper.AnchorPoint = new CCPoint(0.5f, 0.5f); m_pOuterClipper.Position = ContentSize.Center; m_pOuterClipper.RunAction(new CCRepeatForever(new CCRotateBy(1, 45))); m_pOuterClipper.Stencil = target; CCClippingNode holesClipper = new CCClippingNode(); holesClipper.Inverted = true; holesClipper.AlphaThreshold = 0.05f; holesClipper.AddChild(target); m_pHoles = new CCNode(); holesClipper.AddChild(m_pHoles); m_pHolesStencil = new CCNode(); holesClipper.Stencil = m_pHolesStencil; m_pOuterClipper.AddChild(holesClipper); this.AddChild(m_pOuterClipper); this.TouchEnabled = true; }
void CreateSlicedSprites() { float height = originalSize.Height; float width = originalSize.Width; CCPoint offsetPosition = CCPoint.Zero; offsetPosition.X = (float)System.Math.Ceiling(offset.X + (originalSize.Width - spriteRect.Size.Width) / 2); offsetPosition.Y = (float)System.Math.Ceiling(offset.Y + (originalSize.Height - spriteRect.Size.Height) / 2); // If there is no specified center region if (capInsetsInternal == CCRect.Zero) { capInsetsInternal = new CCRect(width / 3, height / 3, width / 3, height / 3); } var originalRect = spriteRect; if (spriteFrameRotated) { originalRect = new CCRect(spriteRect.Origin.X - offsetPosition.Y, spriteRect.Origin.Y - offsetPosition.X, originalSize.Width, originalSize.Height); } else { originalRect = new CCRect(spriteRect.Origin.X - offsetPosition.Y, spriteRect.Origin.Y - offsetPosition.Y, originalSize.Width, originalSize.Height); } float leftWidth = capInsetsInternal.Origin.X; float centerWidth = capInsetsInternal.Size.Width; float rightWidth = originalRect.Size.Width - (leftWidth + centerWidth); float topHeight = capInsetsInternal.Origin.Y; float centerHeight = capInsetsInternal.Size.Height; float bottomHeight = originalRect.Size.Height - (topHeight + centerHeight); // calculate rects // ... top row float x = 0.0f; float y = 0.0f; //why do we need pixelRect? var pixelRect = new CCRect(offsetPosition.X, offsetPosition.Y, spriteRect.Size.Width, spriteRect.Size.Height); // top left var leftTopBoundsOriginal = new CCRect(x, y, leftWidth, topHeight); var leftTopBounds = leftTopBoundsOriginal; // top center x += leftWidth; var centerTopBounds = new CCRect(x, y, centerWidth, topHeight); // top right x += centerWidth; var rightTopBounds = new CCRect(x, y, rightWidth, topHeight); // ... center row x = 0.0f; y = 0.0f; y += topHeight; // center left var leftCenterBounds = new CCRect(x, y, leftWidth, centerHeight); // center center x += leftWidth; var centerBoundsOriginal = new CCRect(x, y, centerWidth, centerHeight); var centerBounds = centerBoundsOriginal; // center right x += centerWidth; var rightCenterBounds = new CCRect(x, y, rightWidth, centerHeight); // ... bottom row x = 0.0f; y = 0.0f; y += topHeight; y += centerHeight; // bottom left var leftBottomBounds = new CCRect(x, y, leftWidth, bottomHeight); // bottom center x += leftWidth; var centerBottomBounds = new CCRect(x, y, centerWidth, bottomHeight); // bottom right x += centerWidth; var rightBottomBoundsOriginal = new CCRect(x, y, rightWidth, bottomHeight); var rightBottomBounds = rightBottomBoundsOriginal; if ((capInsetsInternal.Origin.X + capInsetsInternal.Size.Width) <= originalSize.Width || (capInsetsInternal.Origin.Y + capInsetsInternal.Size.Height) <= originalSize.Height) //in general case it is error but for legacy support we will check it { leftTopBounds = intersectRect(leftTopBounds, pixelRect); centerTopBounds = intersectRect(centerTopBounds, pixelRect); rightTopBounds = intersectRect(rightTopBounds, pixelRect); leftCenterBounds = intersectRect(leftCenterBounds, pixelRect); centerBounds = intersectRect(centerBounds, pixelRect); rightCenterBounds = intersectRect(rightCenterBounds, pixelRect); leftBottomBounds = intersectRect(leftBottomBounds, pixelRect); centerBottomBounds = intersectRect(centerBottomBounds, pixelRect); rightBottomBounds = intersectRect(rightBottomBounds, pixelRect); } else { //it is error but for legacy turn off clip system CCLog.Log("Scale9Sprite capInsetsInternal > originalSize"); } var rotatedLeftTopBoundsOriginal = leftTopBoundsOriginal; var rotatedCenterBoundsOriginal = centerBoundsOriginal; var rotatedRightBottomBoundsOriginal = rightBottomBoundsOriginal; var rotatedCenterBounds = centerBounds; var rotatedRightBottomBounds = rightBottomBounds; var rotatedLeftBottomBounds = leftBottomBounds; var rotatedRightTopBounds = rightTopBounds; var rotatedLeftTopBounds = leftTopBounds; var rotatedRightCenterBounds = rightCenterBounds; var rotatedLeftCenterBounds = leftCenterBounds; var rotatedCenterBottomBounds = centerBottomBounds; var rotatedCenterTopBounds = centerTopBounds; if (!spriteFrameRotated) { CCAffineTransform t = CCAffineTransform.Identity; t = CCAffineTransform.Translate(t, originalRect.Origin.X, originalRect.Origin.Y); rotatedLeftTopBoundsOriginal = CCAffineTransform.Transform(rotatedLeftTopBoundsOriginal, t); rotatedCenterBoundsOriginal = CCAffineTransform.Transform(rotatedCenterBoundsOriginal, t); rotatedRightBottomBoundsOriginal = CCAffineTransform.Transform(rotatedRightBottomBoundsOriginal, t); rotatedCenterBounds = CCAffineTransform.Transform(rotatedCenterBounds, t); rotatedRightBottomBounds = CCAffineTransform.Transform(rotatedRightBottomBounds, t); rotatedLeftBottomBounds = CCAffineTransform.Transform(rotatedLeftBottomBounds, t); rotatedRightTopBounds = CCAffineTransform.Transform(rotatedRightTopBounds, t); rotatedLeftTopBounds = CCAffineTransform.Transform(rotatedLeftTopBounds, t); rotatedRightCenterBounds = CCAffineTransform.Transform(rotatedRightCenterBounds, t); rotatedLeftCenterBounds = CCAffineTransform.Transform(rotatedLeftCenterBounds, t); rotatedCenterBottomBounds = CCAffineTransform.Transform(rotatedCenterBottomBounds, t); rotatedCenterTopBounds = CCAffineTransform.Transform(rotatedCenterTopBounds, t); } else { // set up transformation of coordinates // to handle the case where the sprite is stored rotated // in the spritesheet // log("rotated"); CCAffineTransform t = CCAffineTransform.Identity; t = CCAffineTransform.Translate(t, originalRect.Size.Height + originalRect.Origin.X, originalRect.Origin.Y); t = CCAffineTransform.Rotate(t, 1.57079633f); leftTopBoundsOriginal = CCAffineTransform.Transform(leftTopBoundsOriginal, t); centerBoundsOriginal = CCAffineTransform.Transform(centerBoundsOriginal, t); rightBottomBoundsOriginal = CCAffineTransform.Transform(rightBottomBoundsOriginal, t); centerBounds = CCAffineTransform.Transform(centerBounds, t); rightBottomBounds = CCAffineTransform.Transform(rightBottomBounds, t); leftBottomBounds = CCAffineTransform.Transform(leftBottomBounds, t); rightTopBounds = CCAffineTransform.Transform(rightTopBounds, t); leftTopBounds = CCAffineTransform.Transform(leftTopBounds, t); rightCenterBounds = CCAffineTransform.Transform(rightCenterBounds, t); leftCenterBounds = CCAffineTransform.Transform(leftCenterBounds, t); centerBottomBounds = CCAffineTransform.Transform(centerBottomBounds, t); centerTopBounds = CCAffineTransform.Transform(centerTopBounds, t); rotatedLeftTopBoundsOriginal.Origin = leftTopBoundsOriginal.Origin; rotatedCenterBoundsOriginal.Origin = centerBoundsOriginal.Origin; rotatedRightBottomBoundsOriginal.Origin = rightBottomBoundsOriginal.Origin; rotatedCenterBounds.Origin = centerBounds.Origin; rotatedRightBottomBounds.Origin = rightBottomBounds.Origin; rotatedLeftBottomBounds.Origin = leftBottomBounds.Origin; rotatedRightTopBounds.Origin = rightTopBounds.Origin; rotatedLeftTopBounds.Origin = leftTopBounds.Origin; rotatedRightCenterBounds.Origin = rightCenterBounds.Origin; rotatedLeftCenterBounds.Origin = leftCenterBounds.Origin; rotatedCenterBottomBounds.Origin = centerBottomBounds.Origin; rotatedCenterTopBounds.Origin = centerTopBounds.Origin; } topLeftSize = rotatedLeftTopBoundsOriginal.Size; centerSize = rotatedCenterBoundsOriginal.Size; bottomRightSize = rotatedRightBottomBoundsOriginal.Size; if (spriteFrameRotated) { float offsetX = (rotatedCenterBounds.Origin.X + rotatedCenterBounds.Size.Height / 2) - (rotatedCenterBoundsOriginal.Origin.X + rotatedCenterBoundsOriginal.Size.Height / 2); float offsetY = (rotatedCenterBoundsOriginal.Origin.Y + rotatedCenterBoundsOriginal.Size.Width / 2) - (rotatedCenterBounds.Origin.Y + rotatedCenterBounds.Size.Width / 2); centerOffset.X = -offsetY; centerOffset.Y = offsetX; } else { float offsetX = (rotatedCenterBounds.Origin.X + rotatedCenterBounds.Size.Width / 2) - (rotatedCenterBoundsOriginal.Origin.X + rotatedCenterBoundsOriginal.Size.Width / 2); float offsetY = (rotatedCenterBoundsOriginal.Origin.Y + rotatedCenterBoundsOriginal.Size.Height / 2) - (rotatedCenterBounds.Origin.Y + rotatedCenterBounds.Size.Height / 2); centerOffset.X = offsetX; centerOffset.Y = offsetY; } // Centre if (rotatedCenterBounds.Size.Width > 0 && rotatedCenterBounds.Size.Height > 0) { centerSprite = new CCSprite(scale9Image.Texture, rotatedCenterBounds, spriteFrameRotated); AddProtectedChild(centerSprite); } // Top if (rotatedCenterTopBounds.Size.Width > 0 && rotatedCenterTopBounds.Size.Height > 0) { topSprite = new CCSprite(scale9Image.Texture, rotatedCenterTopBounds, spriteFrameRotated); AddProtectedChild(topSprite); } // Bottom if (rotatedCenterBottomBounds.Size.Width > 0 && rotatedCenterBottomBounds.Size.Height > 0) { bottomSprite = new CCSprite(scale9Image.Texture, rotatedCenterBottomBounds, spriteFrameRotated); AddProtectedChild(bottomSprite); } // Left if (rotatedLeftCenterBounds.Size.Width > 0 && rotatedLeftCenterBounds.Size.Height > 0) { leftSprite = new CCSprite(scale9Image.Texture, rotatedLeftCenterBounds, spriteFrameRotated); AddProtectedChild(leftSprite); } // Right if (rotatedRightCenterBounds.Size.Width > 0 && rotatedRightCenterBounds.Size.Height > 0) { rightSprite = new CCSprite(scale9Image.Texture, rotatedRightCenterBounds, spriteFrameRotated); AddProtectedChild(rightSprite); } // Top left if (rotatedLeftTopBounds.Size.Width > 0 && rotatedLeftTopBounds.Size.Height > 0) { topLeftSprite = new CCSprite(scale9Image.Texture, rotatedLeftTopBounds, spriteFrameRotated); AddProtectedChild(topLeftSprite); } // Top right if (rotatedRightTopBounds.Size.Width > 0 && rotatedRightTopBounds.Size.Height > 0) { topRightSprite = new CCSprite(scale9Image.Texture, rotatedRightTopBounds, spriteFrameRotated); AddProtectedChild(topRightSprite); } // Bottom left if (rotatedLeftBottomBounds.Size.Width > 0 && rotatedLeftBottomBounds.Size.Height > 0) { bottomLeftSprite = new CCSprite(scale9Image.Texture, rotatedLeftBottomBounds, spriteFrameRotated); AddProtectedChild(bottomLeftSprite); } // Bottom right if (rotatedRightBottomBounds.Size.Width > 0 && rotatedRightBottomBounds.Size.Height > 0) { bottomRightSprite = new CCSprite(scale9Image.Texture, rotatedRightBottomBounds, spriteFrameRotated); AddProtectedChild(bottomRightSprite); } }