void OnCapture(object sender) { RemoveChildByTag(childTag); var windowSize = VisibleBoundsWorldspace.Size; // create a render texture, this is what we are going to draw into target = new CCRenderTexture(windowSize, windowSize, CCSurfaceFormat.Color, CCDepthFormat.None, CCRenderTargetUsage.PreserveContents); target.Sprite.Position = windowSize.Center; target.Sprite.AnchorPoint = CCPoint.AnchorMiddle; // begin drawing to the render texture target.BeginWithClear(CCColor4B.Blue); Layer.Visit(); // finish drawing and return context back to the screen target.End(); AddChild(target.Sprite, 0, childTag); target.Sprite.Scale = 0.25f; }
public void renderScreenShot() { var size = Layer.VisibleBoundsWorldspace.Size; var texture = new CCRenderTexture(size, size); CCAffineTransform worldTransform = AffineWorldTransform; texture.Sprite.AnchorPoint = new CCPoint(0, 0); texture.BeginWithClear(CCColor4B.Transparent); Visit(ref worldTransform); 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 override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; // create a render texture, this is what we are going to draw into target = new CCRenderTexture(windowSize, windowSize, CCSurfaceFormat.Color, CCDepthFormat.None, CCRenderTargetUsage.PreserveContents); // Let's clear the rendertarget here so that we start off fresh. // Some platforms do not seem to be initializing the rendertarget color so this will make sure the background shows up colored instead of // what looks like non initialized. Mostly MacOSX for now. target.Clear(0, 0, 0, 255); target.Position = new CCPoint(windowSize.Width / 2, windowSize.Height / 2); // It's possible to modify the RenderTexture blending function by //CCBlendFunc tbf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); //target.Sprite.BlendFunc = tbf; // note that the render texture is a CCNode, and contains a sprite of its texture for convience, // so we can just parent it to the scene like any other CCNode AddChild(target, -1); saveImageMenu.AlignItemsVertically(); saveImageMenu.Position = new CCPoint(windowSize.Width - 80, windowSize.Height - 30); // Register Touch Event var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesMoved = OnTouchesMoved; AddEventListener(touchListener); }
public void renderScreenShot() { var size = CCDirector.SharedDirector.WinSize; var texture = new CCRenderTexture((int)size.Width, (int)size.Height); //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 = CCTypes.CCGreen; sprite.RunAction( CCSequence.FromActions( new CCFadeTo(2, 0), new CCHide() ) ); }
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.Begin(); // 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.Position = new CCPoint(windowSize.Width / 2 + 16, windowSize.Height / 2); AddChild(spriteNonpremulti); AddChild(spritePremulti); AddChild(rend); }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; // create a render texture, this is what we are going to draw into target = new CCRenderTexture(windowSize, windowSize, CCSurfaceFormat.Color, CCDepthFormat.None, CCRenderTargetUsage.PreserveContents); target.Sprite.Position = new CCPoint(windowSize.Width / 2, windowSize.Height / 2); target.Sprite.AnchorPoint = CCPoint.AnchorMiddle; // It's possible to modify the RenderTexture blending function by //CCBlendFunc tbf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); //target.Sprite.BlendFunc = tbf; // note that the render texture is a CCNode, and contains a sprite of its texture for convience, // so we can just parent it to the scene like any other CCNode AddChild(target.Sprite); saveImageMenu.AlignItemsVertically(); saveImageMenu.Position = new CCPoint(windowSize.Width - 80, windowSize.Height - 30); // Register Touch Event var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesMoved = OnTouchesMoved; AddEventListener(touchListener); }
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 RenderTextureSave() { CCSize s = CCDirector.sharedDirector().getWinSize(); // create a render texture, this is what we are going to draw into m_pTarget = CCRenderTexture.renderTextureWithWidthAndHeight((int)s.width, (int)s.height); //m_pTarget->retain(); m_pTarget.position = new CCPoint(s.width / 2, s.height / 2); // note that the render texture is a CCNode, and contains a sprite of its texture for convience, // so we can just parent it to the scene like any other CCNode this.addChild(m_pTarget, -1); // create a brush image to draw into the texture with m_pBrush = CCSprite.spriteWithFile("Images/fire.png"); //m_pBrush->retain(); m_pBrush.Opacity = 20; //this->setIsTouchEnabled(true); isTouchEnabled = true; // Save Image menu CCMenuItemFont.FontSize = 16; CCMenuItem item1 = CCMenuItemFont.itemFromString("Save Image", this, saveImage); CCMenuItem item2 = CCMenuItemFont.itemFromString("Clear", this, clearImage); CCMenu menu = CCMenu.menuWithItems(item1, item2); this.addChild(menu); menu.alignItemsVertically(); menu.position = new CCPoint(s.width - 80, s.height - 30); }
public Button(CCSprite sprite, CCLabel label) : this() { this.ContentSize = sprite.ScaledContentSize; sprite.AnchorPoint = CCPoint.AnchorLowerLeft; label.Position = sprite.ContentSize.Center; // Create the render texture to draw to. It will be the size of the button background sprite var render = new CCRenderTexture(sprite.ContentSize, sprite.ContentSize); // Clear it to any background color you want render.BeginWithClear(CCColor4B.Transparent); // Render the background sprite to the render texture sprite.Visit(); // Render the label to the render texture label.Visit(); // End the rendering render.End(); // Add the button sprite to this node so it can be rendered buttonSprite = render.Sprite; buttonSprite.AnchorPoint = CCPoint.AnchorMiddle; AddChild(this.buttonSprite); }
public override void OnEnter() { base.OnEnter(); var windowSize = Layer.VisibleBoundsWorldspace.Size; CCRenderTexture text = new CCRenderTexture(windowSize, windowSize); AddChild(text, 24); CCDrawNode draw = new CCDrawNode(); // 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)); draw.AnchorPoint = CCPoint.AnchorLowerLeft; text.Begin(); draw.Visit(); text.End(); }
protected override void InitialiseScenes() { base.InitialiseScenes(); var bounds = Layer.VisibleBoundsWorldspace; CCRect viewportRect = Viewport.ViewportInPixels; CCRenderTexture outTexture = new CCRenderTexture(bounds.Size, viewportRect.Size); CCSprite outTexSprite = outTexture.Sprite; var worldTransform = Layer.AffineWorldTransform; outTexture.BeginWithClear(0, 0, 0, 0); OutSceneNodeContainer.Visit(ref worldTransform); outTexture.End(); outTexSprite.AnchorPoint = CCPoint.AnchorMiddle; outTexSprite.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); outTexSprite.BlendFunc = CCBlendFunc.NonPremultiplied; outTexSprite.Opacity = 255; CCAction layerAction = new CCSequence(new CCFadeTo(Duration, 0), new CCCallFunc((Finish))); outTexSprite.RunAction(layerAction); Layer.AddChild(outTexture.Sprite, 3); InSceneNodeContainer.Visible = true; OutSceneNodeContainer.Visible = false; }
public CCTexture2D CreateCharacterTexture() { const int width = 490; const int height = 278; var centerPoint = new CCPoint(width / 2, height / 2); var characterTexture = new CCRenderTexture(width, height); 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(); 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.Position = new CCPoint(windowSize.Width * 0.5f, windowSize.Height * 0.5f); AddChild(rend); }
public RenderTextureTestDepthStencil() { CCSize s = CCDirector.SharedDirector.WinSize; CCSprite sprite = new CCSprite("Images/fire"); sprite.Position = new CCPoint(s.Width * 0.25f, 0); sprite.Scale = 10; CCRenderTexture rend = new CCRenderTexture((int)s.Width, (int)s.Height, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, RenderTargetUsage.DiscardContents); rend.BeginWithClear(0, 0, 0, 0, 0); var save = CCDrawManager.DepthStencilState; CCDrawManager.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.DepthStencilState = new DepthStencilState() { DepthBufferEnable = false, StencilEnable = true, StencilFunction = CompareFunction.NotEqual, StencilPass = StencilOperation.Keep, ReferenceStencil = 1 }; // GL_SRC_ALPHA CCDrawManager.BlendFunc(new CCBlendFunc(OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA)); //! move sprite half width and height, and draw only where not marked sprite.Position = sprite.Position + new CCPoint(sprite.ContentSize.Width * sprite.Scale, sprite.ContentSize.Height * sprite.Scale) * 0.5f; sprite.Visit(); CCDrawManager.DepthStencilState = save; rend.End(); rend.Position = new CCPoint(s.Width * 0.5f, s.Height * 0.5f); AddChild(rend); }
private void SwitchToRenderTexture() { bool areVisualComponentsAlreadyAdded = this.Children != null && this.Children.Contains(visualComponents[0]); var oldPosition = this.Position; if (!areVisualComponentsAlreadyAdded) { // Temporarily add them so we can render the object: foreach (var component in visualComponents) { this.AddChild(component); } } // Create the render texture if it hasn't yet been made: if (renderTexture == null) { // Even though the game is zoomed in to create a pixellated look, we are using // high-resolution textures. Therefore, we want to have our canvas be 2x as big as // the background so fonts don't appear pixellated var pixelResolution = background.ContentSize * 2; var unitResolution = background.ContentSize; renderTexture = new CCRenderTexture(unitResolution, pixelResolution); //renderTexture.Sprite.Scale = .5f; } // We don't want the render target to be a child of this when we update it: if (this.Children != null && this.Children.Contains(renderTexture.Sprite)) { this.Children.Remove(renderTexture.Sprite); } // Move this instance back to the origin so it is rendered inside the render target: this.Position = CCPoint.Zero; renderTexture.BeginWithClear(CCColor4B.Transparent); this.Visit(); renderTexture.End(); // We no longer want the individual components to be drawn, so remove them: foreach (var component in visualComponents) { this.RemoveChild(component); } // Move this back to its original position: this.Position = oldPosition; // add the render target sprite to this: renderTexture.Sprite.AnchorPoint = CCPoint.Zero; this.AddChild(renderTexture.Sprite); }
public RenderTextureIssue937() { /* * 1 2 * A: A1 A2 * * B: B1 B2 * * A1: premulti sprite * A2: premulti render * * B1: non-premulti sprite * B2: non-premulti render */ CCLayerColor background = CCLayerColor.layerWithColor(new ccColor4B(200, 200, 200, 255)); addChild(background); CCSprite spr_premulti = CCSprite.spriteWithFile("Images/fire.png"); spr_premulti.position = new CCPoint(16, 48); CCSprite spr_nonpremulti = CCSprite.spriteWithFile("Images/fire.png"); spr_nonpremulti.position = new CCPoint(16, 16); /* A2 & B2 setup */ CCRenderTexture rend = CCRenderTexture.renderTextureWithWidthAndHeight(32, 64); if (null == rend) { return; } // It's possible to modify the RenderTexture blending function by // [[rend sprite] setBlendFunc:(ccBlendFunc) {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; rend.begin(); spr_premulti.visit(); spr_nonpremulti.visit(); rend.end(); CCSize s = CCDirector.sharedDirector().getWinSize(); /* A1: setup */ spr_premulti.position = new CCPoint(s.width / 2 - 16, s.height / 2 + 16); /* B1: setup */ spr_nonpremulti.position = new CCPoint(s.width / 2 - 16, s.height / 2 - 16); rend.position = new CCPoint(s.width / 2 + 16, s.height / 2); addChild(spr_nonpremulti); addChild(spr_premulti); addChild(rend); }
public RenderTextureIssue937() { /* * 1 2 * A: A1 A2 * * B: B1 B2 * * A1: premulti sprite * A2: premulti render * * B1: non-premulti sprite * B2: non-premulti render */ CCLayerColor background = new CCLayerColor(new CCColor4B(200, 200, 200, 255)); AddChild(background); CCSprite spr_premulti = new CCSprite("Images/fire"); spr_premulti.Position = new CCPoint(16, 48); CCSprite spr_nonpremulti = new CCSprite("Images/fire"); spr_nonpremulti.Position = new CCPoint(16, 16); /* A2 & B2 setup */ CCRenderTexture rend = new CCRenderTexture(32, 64); // 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.Begin(); // A2 spr_premulti.Visit(); // B2 spr_nonpremulti.Visit(); rend.End(); CCSize s = CCDirector.SharedDirector.WinSize; /* A1: setup */ spr_premulti.Position = new CCPoint(s.Width / 2 - 16, s.Height / 2 + 16); /* B1: setup */ spr_nonpremulti.Position = new CCPoint(s.Width / 2 - 16, s.Height / 2 - 16); rend.Position = new CCPoint(s.Width / 2 + 16, s.Height / 2); AddChild(spr_nonpremulti); AddChild(spr_premulti); AddChild(rend); }
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 AddChild(texture); // Render outScene to its texturebuffer texture.BeginWithClear(0, 0, 0, 1); SceneNodeContainerToBeModified.Visit(); texture.End(); // 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); }
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);; }
public GameplayLayer() : base(CCColor4B.Black) { Animations.Init(); renderTexture = new CCRenderTexture(VisibleBoundsWorldspace.Size, VisibleBoundsWorldspace.Size * 2); background = new SpaceBackground(); background.Position = new CCPoint(0, 0); player = new Player(); player.Position = GameParameters.PLAYER_INITIAL_POSITION; player.RocketLaunched += NewRocketHandler; playerCannotMove = false; playerTakesNoDamage = false; playersRocketList = new List <Rocket>(); alienInvadersRocketList = new List <Rocket>(); alienAttackMillis = 0; alienHive = new AlienHive(this.ContentSize, NewRocketHandler); playerLifeHpDisplay = new PlayerLifeHpDisplayNode(ref player); playerLifeHpDisplay.Position = new CCPoint(VisibleBoundsWorldspace.Size.Width, VisibleBoundsWorldspace.Size.Height); renderTexture.BeginWithClear(CCColor4B.Transparent); this.Visit(); renderTexture.End(); this.AddChild(renderTexture.Sprite); renderTexture.Sprite.AddChild(background); renderTexture.Sprite.AddChild(player); foreach (AlienInvader enemy in alienHive.AlienInvadersList) { renderTexture.Sprite.AddChild(enemy); } renderTexture.Sprite.AddChild(playerLifeHpDisplay); Schedule(GameLoop, GameParameters.ANIMATION_FRAME_CHANGE_INTERVAL_SECONDS); }
//OLD_TRANSITION_CREATE_FUNC(CCTransitionProgressRadialCCW) //TRANSITION_CREATE_FUNC(CCTransitionProgressRadialCCW) protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture) { CCSize size = CCDirector.SharedDirector.WinSize; CCProgressTimer node = new CCProgressTimer(texture.Sprite); // but it is flipped upside down so we flip the sprite //node.Sprite.IsFlipY = true; node.Type = CCProgressTimerType.Radial; // Return the radial type that we want to use node.ReverseDirection = false; node.Percentage = 100; node.Position = new CCPoint(size.Width / 2, size.Height / 2); node.AnchorPoint = new CCPoint(0.5f, 0.5f); return(node); }
public override void OnEnter() { base.OnEnter(); SetupTransition(); // create a transparent color layer // in which we are going to add our rendertextures CCSize size = CCDirector.SharedDirector.WinSize; // create the second render texture for outScene CCRenderTexture texture = new CCRenderTexture((int)size.Width, (int)size.Height); texture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); texture.Position = new CCPoint(size.Width / 2, size.Height / 2); texture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer texture.Clear(0, 0, 0, 1); texture.Begin(); m_pSceneToBeModified.Visit(); texture.End(); // Since we've passed the outScene to the texture we don't need it. if (m_pSceneToBeModified == m_pOutScene) { HideOutShowIn(); } // We need the texture in RenderTexture. CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture); // create the blend action CCSequence layerAction = CCSequence.FromActions( new CCProgressFromTo(m_fDuration, m_fFrom, m_fTo), new CCCallFunc(Finish) ); // run the blend action node.RunAction(layerAction); // add the layer (which contains our two rendertextures) to the scene AddChild(node, 2, kCCSceneRadial); }
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(); rtm.Position = VisibleBoundsWorldspace.Center; rtm.AnchorPoint = CCPoint.AnchorMiddle; AddChild(rtm); }
public override void OnEnter() { base.OnEnter(); SetupTransition(); // create a transparent color layer // in which we are going to add our rendertextures CCSize size = CCDirector.SharedDirector.WinSize; // create the second render texture for outScene CCRenderTexture texture = new CCRenderTexture((int) size.Width, (int) size.Height); texture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); texture.Position = new CCPoint(size.Width / 2, size.Height / 2); texture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer texture.Clear(0, 0, 0, 1); texture.Begin(); m_pSceneToBeModified.Visit(); texture.End(); // Since we've passed the outScene to the texture we don't need it. if (m_pSceneToBeModified == m_pOutScene) { HideOutShowIn(); } // We need the texture in RenderTexture. CCProgressTimer node = ProgressTimerNodeWithRenderTexture(texture); // create the blend action CCSequence layerAction = new CCSequence( new CCProgressFromTo(m_fDuration, m_fFrom, m_fTo), new CCCallFunc(Finish) ); // run the blend action node.RunAction(layerAction); // add the layer (which contains our two rendertextures) to the scene AddChild(node, 2, kCCSceneRadial); }
protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture) { CCSize size = CCDirector.SharedDirector.WinSize; CCProgressTimer node = new CCProgressTimer(texture.Sprite); // but it is flipped upside down so we flip the sprite //node.Sprite.IsFlipY = true; node.Type = CCProgressTimerType.Bar; node.Midpoint = new CCPoint(0.5f, 0.5f); node.BarChangeRate = new CCPoint(1, 1); node.Percentage = 100; node.Position = new CCPoint(size.Width / 2, size.Height / 2); node.AnchorPoint = new CCPoint(0.5f, 0.5f); return(node); }
public RenderTextureSave() { CCSize s = CCDirector.SharedDirector.WinSize; // create a render texture, this is what we are going to draw into m_pTarget = new CCRenderTexture((int)s.Width, (int)s.Height, SurfaceFormat.Color, DepthFormat.None, RenderTargetUsage.PreserveContents); // Let's clear the rendertarget here so that we start off fresh. // Some platforms do not seem to be initializing the rendertarget color so this will make sure the background shows up colored instead of // what looks like non initialized. Mostly MacOSX for now. m_pTarget.Clear(0, 0, 0, 255); m_pTarget.Position = new CCPoint(s.Width / 2, s.Height / 2); // It's possible to modify the RenderTexture blending function by //CCBlendFunc tbf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA); //m_pTarget.Sprite.BlendFunc = tbf; // note that the render texture is a CCNode, and contains a sprite of its texture for convience, // so we can just parent it to the scene like any other CCNode AddChild(m_pTarget, -1); // create a brush image to draw into the texture with m_pBrush = new CCSprite("Images/fire"); // It's possible to modify the Brushes blending function by CCBlendFunc bbf = new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE_MINUS_SRC_ALPHA); m_pBrush.BlendFunc = bbf; m_pBrush.Color = new CCColor3B(Color.Red); m_pBrush.Opacity = 20; TouchEnabled = true; // Save Image menu CCMenuItemFont.FontSize = 16; CCMenuItem item1 = new CCMenuItemFont("Save Image", saveImage); CCMenuItem item2 = new CCMenuItemFont("Clear", clearImage); var menu = new CCMenu(item1, item2); AddChild(menu); menu.AlignItemsVertically(); menu.Position = new CCPoint(s.Width - 80, s.Height - 30); }
public DrawPrimitivesWithRenderTextureTest() { CCSize s = CCDirector.SharedDirector.WinSize; CCRenderTexture text = new CCRenderTexture((int)s.Width, (int)s.Height); CCDrawNode draw = new CCDrawNode(); text.AddChild(draw, 10); text.Begin(); // Draw polygons CCPoint[] points = new CCPoint[] { new CCPoint(s.Height / 4, 0), new CCPoint(s.Width, s.Height / 5), new CCPoint(s.Width / 3 * 2, s.Height) }; draw.DrawPolygon(points, points.Length, new CCColor4F(1, 0, 0, 0.5f), 4, new CCColor4F(0, 0, 1, 1)); text.End(); AddChild(text, 24); }
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 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 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 RenderTextureTest() { //if (CCConfiguration.sharedConfiguration().getGlesVersion() <= GLES_VER_1_0) //{ // CCMessageBox("The Opengl ES version is lower than 1.1, and the test may not run correctly.", "Cocos2d-x Hint"); // return; //} CCSize s = CCDirector.sharedDirector().getWinSize(); // create a render texture, this is what we're going to draw into m_target = CCRenderTexture.renderTextureWithWidthAndHeight((int)s.width, (int)s.height); if (null == m_target) { return; } m_target.position = new CCPoint(s.width / 2, s.height / 2); // note that the render texture is a cocosnode, and contains a sprite of it's texture for convience, // so we can just parent it to the scene like any other cocos node addChild(m_target, 1); // create a brush image to draw into the texture with m_brush = CCSprite.spriteWithFile("Images/stars.png"); //m_brush.retain(); ccBlendFunc bf = new ccBlendFunc { src = 1, dst = 0x0303 }; m_brush.BlendFunc = bf; m_brush.Opacity = 20; isTouchEnabled = true; }
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); }
protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture) { CCSize size = CCDirector.SharedDirector.WinSize; CCProgressTimer node = CCProgressTimer.Create(texture.Sprite); // but it is flipped upside down so we flip the sprite //node.Sprite.IsFlipY = true; node.Type = CCProgressTimerType.Radial; // Return the radial type that we want to use node.ReverseDirection = true; node.Percentage = 100; node.Position = new CCPoint(size.Width / 2, size.Height / 2); node.AnchorPoint = new CCPoint(0.5f, 0.5f); return node; }
public override void OnEnter() { base.OnEnter(); // create a transparent color layer // in which we are going to add our rendertextures var color = new CCColor4B(0, 0, 0, 0); CCSize size = CCDirector.SharedDirector.WinSize; CCLayerColor layer = new CCLayerColor(color); // create the first render texture for inScene CCRenderTexture inTexture = new CCRenderTexture((int) size.Width, (int) size.Height); if (null == inTexture) { return; } inTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); inTexture.Position = new CCPoint(size.Width / 2, size.Height / 2); inTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render inScene to its texturebuffer inTexture.Begin(); m_pInScene.Visit(); inTexture.End(); // create the second render texture for outScene CCRenderTexture outTexture = new CCRenderTexture((int) size.Width, (int) size.Height); outTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); outTexture.Position = new CCPoint(size.Width / 2, size.Height / 2); outTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer outTexture.Begin(); m_pOutScene.Visit(); outTexture.End(); // create blend functions var blend1 = new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE); // inScene will lay on background and will not be used with alpha var blend2 = CCBlendFunc.NonPremultiplied; // we are going to blend outScene via alpha // set blendfunctions inTexture.Sprite.BlendFunc = blend1; outTexture.Sprite.BlendFunc = blend2; // add render textures to the layer layer.AddChild(inTexture); layer.AddChild(outTexture); // initial opacity: inTexture.Sprite.Opacity = 255; outTexture.Sprite.Opacity = 255; // create the blend action CCAction layerAction = CCSequence.FromActions ( new CCFadeTo (m_fDuration, 0), new CCCallFunc((HideOutShowIn)), new CCCallFunc((Finish)) ); //// run the blend action outTexture.Sprite.RunAction(layerAction); // add the layer (which contains our two rendertextures) to the scene AddChild(layer, 2, kSceneFade); }
protected override void InitialiseScenes() { base.InitialiseScenes(); // create a transparent color layer // in which we are going to add our rendertextures var color = new CCColor4B(0, 0, 0, 0); var bounds = Layer.VisibleBoundsWorldspace; CCRect viewportRect = Viewport.ViewportInPixels; // create the first render texture for inScene CCRenderTexture inTexture = new CCRenderTexture(bounds.Size, viewportRect.Size); if (null == inTexture) { return; } inTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); inTexture.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); inTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(inTexture); // render inScene to its texturebuffer inTexture.Begin(); InSceneNodeContainer.Visit(); inTexture.End(); // create the second render texture for outScene CCRenderTexture outTexture = new CCRenderTexture(bounds.Size, viewportRect.Size); outTexture.Sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); outTexture.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); outTexture.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(outTexture); // render outScene to its texturebuffer outTexture.Begin(); OutSceneNodeContainer.Visit(); outTexture.End(); // create blend functions var blend1 = new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE); // inScene will lay on background and will not be used with alpha var blend2 = CCBlendFunc.NonPremultiplied; // we are going to blend outScene via alpha inTexture.Sprite.BlendFunc = blend1; outTexture.Sprite.BlendFunc = blend2; inTexture.Sprite.Opacity = 255; outTexture.Sprite.Opacity = 255; CCAction layerAction = new CCSequence ( new CCFadeTo (Duration, 0), new CCCallFunc((Finish)) ); outTexture.Sprite.RunAction(layerAction); InSceneNodeContainer.Visible = false; OutSceneNodeContainer.Visible = false; }
protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture) { CCSize size = CCDirector.SharedDirector.WinSize; CCProgressTimer node = CCProgressTimer.Create(texture.Sprite); // but it is flipped upside down so we flip the sprite //node.Sprite.IsFlipY = true; node.Type = CCProgressTimerType.Bar; node.Midpoint = new CCPoint(1, 0); node.BarChangeRate = new CCPoint(1, 0); node.Percentage = 100; node.Position = new CCPoint(size.Width / 2, size.Height / 2); node.AnchorPoint = new CCPoint(0.5f, 0.5f); return node; }
protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture) { var bounds = Layer.VisibleBoundsWorldspace; CCProgressTimer node = new CCProgressTimer(texture.Sprite); // but it is flipped upside down so we flip the sprite //node.Sprite.IsFlipY = true; node.Type = CCProgressTimerType.Bar; node.Midpoint = new CCPoint(0.5f, 0.5f); node.BarChangeRate = new CCPoint(1, 1); node.Percentage = 100; node.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); node.AnchorPoint = CCPoint.AnchorMiddle; return node; }
protected abstract CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture);
protected override CCProgressTimer ProgressTimerNodeWithRenderTexture(CCRenderTexture texture) { var bounds = Layer.VisibleBoundsWorldspace; CCProgressTimer node = new CCProgressTimer(texture.Sprite); // but it is flipped upside down so we flip the sprite //node.Sprite.IsFlipY = true; node.Type = CCProgressTimerType.Radial; // Return the radial type that we want to use node.ReverseDirection = true; node.Percentage = 100; node.Position = new CCPoint(bounds.Origin.X + bounds.Size.Width / 2, bounds.Size.Height / 2); node.AnchorPoint = CCPoint.AnchorMiddle; return node; }