public override void OnEnter() { base.OnEnter(); CCActionInterval effect = (new CCSequence(new CCDelayTime(2.0f), new CCShaky3D(5.0f, new CCGridSize(5, 5), 16, false))); // cleanup CCNode bg = GetChildByTag(EffectAdvanceScene.kTagBackground); RemoveChild(bg, true); // background CCLayerColor layer = new CCLayerColor(new CCColor4B(255, 0, 0, 255)); AddChild(layer, -10); CCSprite sprite = new CCSprite("Images/grossini"); sprite.Position = new CCPoint(50, 80); layer.AddChild(sprite, 10); // foreground CCLayerColor layer2 = new CCLayerColor(new CCColor4B(0, 255, 0, 255)); CCSprite fog = new CCSprite("Images/Fog"); var bf = new CCBlendFunc { Source = CCOGLES.GL_SRC_ALPHA, Destination = CCOGLES.GL_ONE_MINUS_SRC_ALPHA }; fog.BlendFunc = bf; layer2.AddChild(fog, 1); AddChild(layer2, 1); layer2.RunAction(new CCRepeatForever(effect)); }
public override void OnEnter() { base.OnEnter(); var effect = new CCSequence(new CCDelayTime(2.0f), new CCShaky3D(5.0f, new CCGridSize(5, 5), 16, false)); // cleanup RemoveChild(bgNode, true); // background var layer = new CCLayerColor(new CCColor4B(255, 0, 0, 255)); AddChild(layer, -10); var sprite = new CCSprite("Images/grossini"); sprite.Position = new CCPoint(50, 80); layer.AddChild(sprite, 10); // foreground var layer2Node = new CCNode(); var layer2 = new CCLayerColor(new CCColor4B(0, 255, 0, 255)); var fog = new CCSprite("Images/Fog"); var bf = new CCBlendFunc { Source = CCOGLES.GL_SRC_ALPHA, Destination = CCOGLES.GL_ONE_MINUS_SRC_ALPHA }; fog.BlendFunc = bf; layer2.AddChild(fog, 1); AddChild(layer2Node, 1); layer2Node.AddChild(layer2); layer2Node.RepeatForever(effect); }
protected override void OnHandlePropTypeBlendFunc(CCNode node, CCNode parent, string propertyName, CCBlendFunc blendFunc, CCBReader reader) { if (propertyName == PROPERTY_BLENDFUNC) { ((CCLabelBMFont) node).BlendFunc = blendFunc; } else { base.OnHandlePropTypeBlendFunc(node, parent, propertyName, blendFunc, reader); } }
protected override void OnHandlePropTypeBlendFunc(CCNode node, CCNode parent, string propertyName, CCBlendFunc blendFunc, CCBReader reader) { if (propertyName == PROPERTY_BLENDFUNC) { // TODO Not exported by CocosBuilder yet! // ((CCScale9Sprite )node).setBlendFunc(blendFunc); } else { base.OnHandlePropTypeBlendFunc(node, parent, propertyName, blendFunc, reader); } }
public override void OnEnter() { base.OnEnter(); var effect = new CCSequence(new CCDelayTime(2.0f), new CCShaky3D(5.0f, new CCGridSize(5, 5), 16, false)); // cleanup contentLayer.RemoveChild(bgNode, true); // background var layer = new CCDrawNode(); layer.Color = CCColor3B.Red; layer.Opacity = 255; layer.DrawRect(VisibleBoundsWorldspace); AddChild(layer, -10); var sprite = new CCSprite("Images/grossini"); sprite.Position = new CCPoint(50, 80); layer.AddChild(sprite, 10); // foreground var layer2BaseGrid = new CCNodeGrid(); var layer2 = new CCDrawNode(); layer2.Color = CCColor3B.Green; layer2.Opacity = 255; layer2.DrawRect(VisibleBoundsWorldspace); var fog = new CCSprite("Images/Fog"); var bf = new CCBlendFunc { Source = CCOGLES.GL_SRC_ALPHA, Destination = CCOGLES.GL_ONE_MINUS_SRC_ALPHA }; fog.BlendFunc = bf; layer2.AddChild(fog, 1); AddChild(layer2BaseGrid, 1); layer2BaseGrid.AddChild(layer2); layer2BaseGrid.RepeatForever(effect); }
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); }
void UpdateBlendFunc(CCTexture2D texture) { if (texture == null) { _blendFunc = CCBlendFunc.AlphaBlend; opacityModifyRGB = true; } else { // it is possible to have an untextured sprite if (!texture.HasPremultipliedAlpha) { _blendFunc = CCBlendFunc.NonPremultiplied; opacityModifyRGB = false; } else { _blendFunc = CCBlendFunc.AlphaBlend; opacityModifyRGB = true; } } }
public RenderTextureSave() { // create a brush image to draw into the texture with brush = 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); brush.BlendFunc = bbf; brush.Color = CCColor3B.Red; brush.Opacity = 20; // Save image menu CCMenuItemFont.FontSize = 16; CCMenuItemFont.FontName = "arial"; CCMenuItem item1 = new CCMenuItemFont("Save Image", SaveImage); CCMenuItem item2 = new CCMenuItemFont("Clear", ClearImage); saveImageMenu = new CCMenu(item1, item2); AddChild(saveImageMenu); }
protected override void OnHandlePropTypeBlendFunc(CCNode node, CCNode parent, string propertyName, CCBlendFunc blendFunc, CCBReader reader) { if (propertyName == PROPERTY_BLENDFUNC) { ((CCLabelBMFont)node).BlendFunc = blendFunc; } else { base.OnHandlePropTypeBlendFunc(node, parent, propertyName, blendFunc, reader); } }
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 = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); // OGLES.GL_SRC_ALPHA, OGLES.GL_ONE_MINUS_SRC_ALPHA); // 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 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; }
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); }