public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; spritePremulti.Position = new CCPoint(16, 48); spriteNonpremulti.Position = new CCPoint(16, 16); CCSize rendSize = new CCSize(32, 64); /* A2 & B2 setup */ CCRenderTexture rend = new CCRenderTexture(rendSize,rendSize); // It's possible to modify the RenderTexture blending function by // CCBlendFunc bf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); // rend.Sprite.BlendFunc = bf; rend.BeginWithClear(CCColor4B.Transparent); // A2 spritePremulti.Visit(); // B2 spriteNonpremulti.Visit(); rend.End(); /* A1: setup */ spritePremulti.Position = new CCPoint(windowSize.Width / 2 - 16, windowSize.Height / 2 + 16); /* B1: setup */ spriteNonpremulti.Position = new CCPoint(windowSize.Width / 2 - 16, windowSize.Height / 2 - 16); rend.Sprite.Position = new CCPoint(windowSize.Width / 2 + 16, windowSize.Height / 2); AddChild(spriteNonpremulti); AddChild(spritePremulti); AddChild(rend.Sprite); }
void AfterDraw() { if (ChildClippingMode != CCClipMode.None) { if (ChildClippingMode == CCClipMode.BoundsWithRenderTarget) { renderTexture.End(); Window.DrawManager.PopMatrix(); } if (restoreScissor) { Window.DrawManager.ScissorRectEnabled = true; restoreScissor = false; } else { Window.DrawManager.ScissorRectEnabled = false; } if (ChildClippingMode == CCClipMode.BoundsWithRenderTarget) { renderTexture.Sprite.Visit(); } } }
public SpriteWithColor(CCColor4B bgColor, CCSize textureSizeInPixels) : base () { // 1: Create new CCRenderTexture CCRenderTexture rt = new CCRenderTexture(textureSizeInPixels, textureSizeInPixels); // 2: Call CCRenderTexture:begin rt.BeginWithClear(bgColor); // 3: Draw into the texture // You'll add this later GenerateGradient(textureSizeInPixels); var noise = new CCSprite("images/Noise.png"); noise.AnchorPoint = CCPoint.AnchorLowerLeft; noise.Position = CCPoint.Zero; noise.BlendFunc = new CCBlendFunc(CCOGLES.GL_DST_COLOR, CCOGLES.GL_ZERO); noise.Texture.SamplerState = Microsoft.Xna.Framework.Graphics.SamplerState.LinearWrap; // To get the linear wrap to work correctly we have to set the TextureRectInPixels as well as ContentSize noise.TextureRectInPixels = new CCRect(0, 0, textureSizeInPixels.Width, textureSizeInPixels.Height); noise.ContentSize = noise.TextureRectInPixels.Size; noise.Visit(); // 4: Call CCRenderTexture:end rt.End(); this.Texture = rt.Texture; }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; CCSprite sprite = new CCSprite("Images/fire"); sprite.Position = new CCPoint(windowSize.Width * 0.25f, 0); sprite.Scale = 10; CCRenderTexture rend = new CCRenderTexture(windowSize, windowSize, CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8, CCRenderTargetUsage.DiscardContents); rend.BeginWithClear(0, 0, 0, 0, 0); // var save = CCDrawManager.SharedDrawManager.DepthStencilState; // // CCDrawManager.SharedDrawManager.DepthStencilState = new DepthStencilState() // { // ReferenceStencil = 1, // // DepthBufferEnable = false, // StencilEnable = true, // StencilFunction = CompareFunction.Always, // StencilPass = StencilOperation.Replace, // // TwoSidedStencilMode = true, // CounterClockwiseStencilFunction = CompareFunction.Always, // CounterClockwiseStencilPass = StencilOperation.Replace, // }; sprite.Visit(); // CCDrawManager.SharedDrawManager.DepthStencilState = new DepthStencilState() // { // DepthBufferEnable = false, // StencilEnable = true, // StencilFunction = CompareFunction.NotEqual, // StencilPass = StencilOperation.Keep, // ReferenceStencil = 1 // }; // CCDrawManager.SharedDrawManager.BlendFunc(new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE_MINUS_SRC_ALPHA)); sprite.Position = sprite.Position + new CCPoint(sprite.ContentSize.Width * sprite.ScaleX, sprite.ContentSize.Height * sprite.ScaleY) * 0.5f; sprite.Visit(); // CCDrawManager.SharedDrawManager.DepthStencilState = save; rend.End(); rend.Sprite.Position = new CCPoint(windowSize.Width * 0.5f, windowSize.Height * 0.5f); AddChild(rend.Sprite); }
protected override void InitialiseScenes() { if (Layer == null || Viewport == null) { return; } base.InitialiseScenes(); SetupTransition(); // create a transparent color layer // in which we are going to add our rendertextures var bounds = Layer.VisibleBoundsWorldspace; CCRect viewportRect = Viewport.ViewportInPixels; // create the second render texture for outScene CCRenderTexture texture = new CCRenderTexture(bounds.Size, viewportRect.Size); texture.Position = bounds.Center; texture.AnchorPoint = CCPoint.AnchorMiddle; // Temporarily add render texture to get layer/scene properties Layer.AddChild(texture); texture.Visible = false; // Render outScene to its texturebuffer texture.BeginWithClear(0, 0, 0, 1); SceneNodeContainerToBeModified.Visit(); texture.End(); texture.Visible = true; // No longer want to render texture RemoveChild(texture); // Since we've passed the outScene to the texture we don't need it. if (SceneNodeContainerToBeModified == OutSceneNodeContainer) { HideOutShowIn(); } CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture); // create the blend action var layerAction = new CCProgressFromTo(Duration, From, To); // add the layer (which contains our two rendertextures) to the scene AddChild(node, 2, SceneRadial); // run the blend action node.RunAction(layerAction); }
protected override void InitialiseScenes() { if (Layer == null || Viewport == null) return; base.InitialiseScenes(); SetupTransition(); // create a transparent color layer // in which we are going to add our rendertextures var bounds = Layer.VisibleBoundsWorldspace; CCRect viewportRect = Viewport.ViewportInPixels; // create the second render texture for outScene CCRenderTexture texture = new CCRenderTexture(bounds.Size, viewportRect.Size); texture.Position = bounds.Center; texture.AnchorPoint = CCPoint.AnchorMiddle; // Temporarily add render texture to get layer/scene properties Layer.AddChild(texture); texture.Visible = false; // Render outScene to its texturebuffer texture.BeginWithClear(0, 0, 0, 1); SceneNodeContainerToBeModified.Visit(); texture.End(); texture.Visible = true; // No longer want to render texture RemoveChild(texture); // Since we've passed the outScene to the texture we don't need it. if (SceneNodeContainerToBeModified == OutSceneNodeContainer) { HideOutShowIn(); } CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture); // create the blend action var layerAction = new CCProgressFromTo(Duration, From, To); // add the layer (which contains our two rendertextures) to the scene AddChild(node, 2, SceneRadial); // run the blend action node.RunAction(layerAction); }
protected override void InitialiseScenes() { if (Layer == null) { return; } base.InitialiseScenes(); SetupTransition(); // create a transparent color layer // in which we are going to add our rendertextures var bounds = Layer.VisibleBoundsWorldspace; CCRect viewportRect = new CCRect(Viewport.Bounds); // create the second render texture for outScene CCRenderTexture texture = new CCRenderTexture(bounds.Size, viewportRect.Size); texture.Sprite.Position = bounds.Center; texture.Sprite.AnchorPoint = CCPoint.AnchorMiddle; // Render outScene to its texturebuffer texture.BeginWithClear(0, 0, 0, 255); var worldTransform = SceneNodeContainerToBeModified.AffineWorldTransform; SceneNodeContainerToBeModified.Visit(ref worldTransform); texture.End(); // Since we've passed the outScene to the texture we don't need it. if (SceneNodeContainerToBeModified == OutSceneNodeContainer) { HideOutShowIn(); } CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture); // create the blend action var layerAction = new CCProgressFromTo(Duration, From, To); // add the layer (which contains our two rendertextures) to the scene Layer.AddChild(node, 2); // run the blend action node.RunAction(layerAction); }
public void NeedsLayout() { OnSprite.Position = new CCPoint(OnSprite.ContentSize.Width / 2 + sliderXPosition, OnSprite.ContentSize.Height / 2); OffSprite.Position = new CCPoint(OnSprite.ContentSize.Width + OffSprite.ContentSize.Width / 2 + sliderXPosition, OffSprite.ContentSize.Height / 2); ThumbSprite.Position = new CCPoint(OnSprite.ContentSize.Width + sliderXPosition, MaskSprite.ContentSize.Height / 2); if (OnLabel != null) { OnLabel.Position = new CCPoint(OnSprite.Position.X - ThumbSprite.ContentSize.Width / 6, OnSprite.ContentSize.Height / 2); } if (OffLabel != null) { OffLabel.Position = new CCPoint(OffSprite.Position.X + ThumbSprite.ContentSize.Width / 6, OffSprite.ContentSize.Height / 2); } var rt = new CCRenderTexture( MaskSprite.TextureRectInPixels.Size, MaskSprite.TextureRectInPixels.Size, CCSurfaceFormat.Color, CCDepthFormat.None, CCRenderTargetUsage.DiscardContents ); rt.BeginWithClear(0, 0, 0, 0); OnSprite.Visit(); OffSprite.Visit(); if (OnLabel != null) { OnLabel.Visit(); } if (OffLabel != null) { OffLabel.Visit(); } MaskSprite.AnchorPoint = new CCPoint(0, 0); MaskSprite.BlendFunc = new CCBlendFunc(CCOGLES.GL_ZERO, CCOGLES.GL_SRC_ALPHA); MaskSprite.Visit(); rt.End(); Texture = rt.Sprite.Texture; ContentSize = MaskSprite.ContentSize; }
public StripeWithColor(CCColor4B c1, CCColor4B c2, CCSize textureSizeInPixels, int nStripes) : base () { // 1: Create new CCRenderTexture CCRenderTexture rt = new CCRenderTexture(textureSizeInPixels, textureSizeInPixels); // 2: Call CCRenderTexture:begin rt.BeginWithClear(c1); // 3: Draw into the texture // You'll add this later GenerateStripes(textureSizeInPixels, c2, nStripes); var noise = new CCSprite("images/Noise.png"); noise.AnchorPoint = CCPoint.AnchorLowerLeft; noise.BlendFunc = new CCBlendFunc(CCOGLES.GL_DST_COLOR, CCOGLES.GL_ZERO); noise.Visit(); // 4: Call CCRenderTexture:end rt.End(); this.Texture = rt.Texture; }
public LabelSystemFontRenderTexture() { Color = new CCColor3B(200, 191, 231); Opacity = 255; label1 = new CCLabel("Visit Rendering", "fonts/MorrisRoman-Black.ttf", 30, CCLabelFormat.SystemFont) { Color = CCColor3B.Orange, AnchorPoint = CCPoint.AnchorMiddleLeft, Dimensions = size, }; label1.LabelFormat.Alignment = CCTextAlignment.Center; txtLabel = new CCRenderTexture (size, size); txtLabel.BeginWithClear (CCColor4B.AliceBlue); label1.Visit (); txtLabel.End (); AddChild(txtLabel.Sprite); }
public override void OnEnter() { base.OnEnter(); CCDrawNode circle = new CCDrawNode(); circle.DrawSolidCircle(new CCPoint(150.0f, 150.0f), 75.0f, new CCColor4B(255, 255, 255, 255)); CCRenderTexture rtm = new CCRenderTexture(new CCSize(200.0f, 200.0f), new CCSize(200.0f, 200.0f), CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8); rtm.BeginWithClear(CCColor4B.Orange); circle.Visit(); // Draw to rendertarget rtm.End(); // Create a new sprite from the render target texture var sprite = new CCSprite(rtm.Texture); sprite.Position = VisibleBoundsWorldspace.Center; AddChild(sprite); }
public override void OnEnter() { base.OnEnter(); CCDrawNode circle = new CCDrawNode(); circle.DrawSolidCircle(new CCPoint(150.0f, 150.0f), 75.0f, new CCColor4B(255, 255, 255, 255)); CCRenderTexture rtm = new CCRenderTexture(new CCSize(200.0f, 200.0f), new CCSize(200.0f, 200.0f), CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8); rtm.BeginWithClear(CCColor4B.Orange); circle.Visit(); rtm.End(); // Make sure our children nodes get visited rtm.Sprite.Position = VisibleBoundsWorldspace.Center; rtm.Sprite.AnchorPoint = CCPoint.AnchorMiddle; AddChild(rtm.Sprite); }
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 void renderScreenShot() { var size = Layer.VisibleBoundsWorldspace.Size; var texture = new CCRenderTexture(size,size); //var texture = new CCRenderTexture(512, 512); texture.AnchorPoint = new CCPoint(0, 0); texture.Begin(); Visit(); texture.End(); CCSprite sprite = new CCSprite(texture.Sprite.Texture); //sprite.Position = new CCPoint(256, 256); sprite.Position = new CCPoint(size.Width/2, size.Height / 2); sprite.Opacity = 182; //sprite.IsFlipY = true; AddChild(sprite, 999999); sprite.Color = CCColor3B.Green; sprite.RunAction( new CCSequence( new CCFadeTo (2, 0), new CCHide() ) ); }
public CCTexture2D CreateCharacterTexture(CCDirector director) { const int width = 490; const int height = 278; CCSize rendSize = new CCSize(width, height); var centerPoint = new CCPoint(width / 2, height / 2); var characterTexture = new CCRenderTexture(rendSize, rendSize); characterTexture.BeginWithClear(100, 0, 0, 0); var bodySprite = CreateCustomisationSprite(); bodySprite.Position = centerPoint; bodySprite.Visit(); var armorSprite = CreateCustomisationSprite(); armorSprite.Position = centerPoint; armorSprite.Visit(); var eyesSprite = CreateCustomisationSprite(); eyesSprite.Position = centerPoint; eyesSprite.Visit(); var noseSprite = CreateCustomisationSprite(); noseSprite.Position = centerPoint; noseSprite.Visit(); var hairSprite = CreateCustomisationSprite(); hairSprite.Position = centerPoint; hairSprite.Visit(); var moustacheSprite = CreateCustomisationSprite(); moustacheSprite.Position = centerPoint; moustacheSprite.Visit(); var beardSprite = CreateCustomisationSprite(); beardSprite.Position = centerPoint; beardSprite.Visit(); var helmutSprite = CreateCustomisationSprite(); helmutSprite.Position = centerPoint; helmutSprite.Visit(); var weaponSprite = CreateCustomisationSprite(); weaponSprite.Position = centerPoint; weaponSprite.Visit(); characterTexture.End(); return characterTexture.Sprite.Texture; }
public override void OnEnter() { base.OnEnter(); var windowSize = Layer.VisibleBoundsWorldspace.Size; CCRenderTexture text = new CCRenderTexture(windowSize,windowSize); AddChild(text, 24); CCDrawNode draw = new CCDrawNode(); text.AddChild(draw, 10); text.Begin(); // Draw polygons CCPoint[] points = new CCPoint[] { new CCPoint(windowSize.Height / 4, 0), new CCPoint(windowSize.Width, windowSize.Height / 5), new CCPoint(windowSize.Width / 3 * 2, windowSize.Height) }; draw.DrawPolygon(points, points.Length, new CCColor4F(1, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1)); text.End(); }
void SaveImage(object sender) { RemoveChildByTag(spriteTag); var renderSize = canvasNode.BoundingRect.Size; var rtm = new CCRenderTexture(renderSize, renderSize); rtm.BeginWithClear(CCColor4B.Green); canvasNode.Position -= canvasNode.BoundingRect.Origin; canvasNode.Visit(); rtm.End(); canvasNode.Position = CCPoint.Zero; rtm.Texture.IsAntialiased = true; rtm.Sprite.AnchorPoint = CCPoint.AnchorLowerLeft; rtm.Sprite.Opacity = 127; AddChild(rtm.Sprite, 50, spriteTag); ; }