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); }
void SaveImage(object sender) { RemoveChildByTag(spriteTag); var renderSize = canvasNode.BoundingRect.Size; var renderOrigin = canvasNode.BoundingRect.Origin; // here we calculate the translation of the rendering. It should be the offset of BoundingRect Origin // this will then be passed to the Visit(ref CCAffineTransform) method. var translate = CCAffineTransform.Translate(canvasNode.AffineWorldTransform, -renderOrigin.X, -renderOrigin.Y); var rtm = new CCRenderTexture(renderSize, renderSize); rtm.BeginWithClear(CCColor4B.Green); canvasNode.Visit(ref translate); rtm.End(); rtm.Texture.IsAntialiased = true; rtm.Sprite.AnchorPoint = CCPoint.AnchorLowerLeft; rtm.Sprite.Opacity = 127; AddChild(rtm.Sprite, 50, spriteTag);; }
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; }
public override void Visit(ref CCAffineTransform parentWorldTransform) { if (positionsAreDirty) { UpdatePositions(); AdjustScale9ImagePosition(); positionsAreDirty = false; } var localTransform = AffineLocalTransform; var worldTransform = CCAffineTransform.Identity; CCAffineTransform.Concat(ref localTransform, ref parentWorldTransform, out worldTransform); if (isScale9Enabled) { for (var j = 0; j < protectedChildren.Count; j++) { var node = protectedChildren[j] as CCSprite; if (node != null) { node.Visit(ref worldTransform); } else { break; } } } else { if (scale9Image != null) { scale9Image.Visit(ref worldTransform); } } base.Visit(ref parentWorldTransform); }
void OnTouchesMoved(List <CCTouch> touches, CCEvent touchEvent) { CCAffineTransform worldTransform = AffineWorldTransform; CCTouch touch = touches[0]; CCPoint start = touch.Location; CCPoint end = touch.PreviousLocation; // begin drawing to the render texture target.Begin(); // for extra points, we'll draw this smoothly from the last position and vary the sprite's // scale/rotation/offset float distance = CCPoint.Distance(start, end); if (distance > 1) { var d = (int)distance; for (int i = 0; i < d; i++) { float difx = end.X - start.X; float dify = end.Y - start.Y; float delta = i / distance; brush.Position = new CCPoint(start.X + (difx * delta), start.Y + (dify * delta)); brush.Rotation = CCRandom.Next() % 360; float r = (CCRandom.Next() % 50 / 50f) + 0.25f; brush.Scale = r; // Comment out the following line to show just the initial red color set brush.Color = new CCColor3B((byte)(CCRandom.Next() % 127 + 128), 255, 255); // Call visit to draw the brush, don't call draw.. brush.Visit(ref worldTransform); } } // finish drawing and return context back to the screen target.End(); }
/// <summary> /// /// </summary> /// <param name="worldTransform"></param> protected override void VisitRenderer(ref CCAffineTransform worldTransform) { base.VisitRenderer(ref worldTransform); Renderer.AddCommand(m_renderCommand); }
static CCAffineTransform b2BodyToParentTransform(CCNode node, LHPhysicsProtocolImp physicsImp) { return(CCAffineTransform.Concat(physicsImp.absoluteTransform(), CCAffineTransform.Invert(NodeToB2BodyTransform(node.Parent)))); }
/// <summary> /// Creates an open <see cref="GraphicsPath"/> from a transformed copy of the path with a given <see cref="Pen"/>. /// </summary> /// <param name="pen">The pen to stroke the path with.</param> /// <param name="transform">The transform matrix to apply to all of the points in the path.</param> /// <returns>A computed <see cref="GraphicsPath"/>.</returns> public GraphicsPath Stroke(Pen pen, CCAffineTransform transform) { return(Stroke(pen, transform, PathType.Open)); }
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); } }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { base.VisitRenderer(ref worldTransform); Renderer.AddCommand(new CCCustomCommand(worldTransform.Tz, worldTransform, RenderTouchPoint)); }
protected override void VisitRenderer(ref CCAffineTransform worldTransform) { Renderer.AddCommand(new CCCustomCommand(worldTransform.Tz, worldTransform, RenderDrawPrimTest)); }
public override void Visit(ref CCAffineTransform parentWorldTransform) { if (positionsAreDirty) { UpdatePositions(); AdjustScale9ImagePosition(); positionsAreDirty = false; } var localTransform = AffineLocalTransform; var worldTransform = CCAffineTransform.Identity; CCAffineTransform.Concat(ref localTransform, ref parentWorldTransform, out worldTransform); if (isScale9Enabled) { for (var j = 0; j < protectedChildren.Count; j++) { var node = protectedChildren[j] as CCSprite; if (node != null) { node.Visit(ref worldTransform); } else break; } } else { if (scale9Image != null) { scale9Image.Visit(ref worldTransform); } } base.Visit(ref parentWorldTransform); }