public override void OnEnter() { base.OnEnter(); CCActionInterval effect = (CCSequence.FromActions(new CCDelayTime (2.0f), new CCShaky3D(16, false, new CCGridSize(5, 5), 5.0f))); // 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)); }
protected virtual bool InitWithFade(float fade, float minSeg, float stroke, CCColor3B color, CCTexture2D texture) { Position = CCPoint.Zero; AnchorPoint = CCPoint.Zero; IgnoreAnchorPointForPosition = true; m_bStartingPositionInitialized = false; m_tPositionR = CCPoint.Zero; m_bFastMode = true; m_fMinSeg = (minSeg == -1.0f) ? stroke / 5.0f : minSeg; m_fMinSeg *= m_fMinSeg; m_fStroke = stroke; m_fFadeDelta = 1.0f / fade; m_uMaxPoints = (int)(fade * 60.0f) + 2; m_uNuPoints = 0; m_pPointState = new float[m_uMaxPoints]; m_pPointVertexes = new CCPoint[m_uMaxPoints]; m_pVertices = new CCV3F_C4B_T2F[(m_uMaxPoints + 1) * 2]; // Set blend mode m_tBlendFunc = CCBlendFunc.NonPremultiplied; Texture = texture; Color = color; ScheduleUpdate(); return(true); }
private void UpdateBlendFunc() { if (!m_pobTextureAtlas.Texture.HasPremultipliedAlpha) { m_blendFunc = CCBlendFunc.NonPremultiplied; } }
public override bool Init() { base.Init(); m_sBlendFunc = CCBlendFunc.AlphaBlend; m_pVertices = new CCRawList <VertexPositionColor>(512); return(true); }
//protected bool m_opacityChanged; public CCLayerColor() { m_cOpacity = 0; m_tColor = new CCColor3B(0, 0, 0); // default blend function m_tBlendFunc = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); Init(); }
public override bool Init() { base.Init(); m_sBlendFunc = CCBlendFunc.AlphaBlend; m_pVertices = new CCRawList<VertexPositionColor>(512); return true; }
//protected bool m_opacityChanged; public CCLayerColor() { m_cOpacity = 0; m_tColor = new CCColor3B(0, 0, 0); // default blend function m_tBlendFunc = new CCBlendFunc(CCMacros.CCDefaultSourceBlending, CCMacros.CCDefaultDestinationBlending); Init (); }
/* * init with CCTexture2D */ public bool InitWithTexture(CCTexture2D tex, int capacity) { TextureAtlas.InitWithTexture(tex, capacity); // no lazy alloc in this node m_pChildren = new CCRawList <CCNode>(capacity); m_tBlendFunc = CCBlendFunc.AlphaBlend; return(true); }
/* * init with CCTexture2D */ public bool InitWithTexture(CCTexture2D tex, int capacity) { TextureAtlas.InitWithTexture(tex, capacity); // no lazy alloc in this node m_pChildren = new CCRawList<CCNode>(capacity); m_tBlendFunc = CCBlendFunc.AlphaBlend; return true; }
public static void BlendFunc(CCBlendFunc blendFunc) { // It looks like the blend state is being reset somewhere so this check of not setting // the blend states is causing multiple problems. Took this check out and setting the // blend state seems the correct modification for now. //if (m_currBlend.Destination != blendFunc.Destination || m_currBlend.Source != blendFunc.Source) //{ BlendState bs = null; if (blendFunc.Source == OGLES.GL_ONE && blendFunc.Destination == OGLES.GL_ONE_MINUS_SRC_ALPHA) { bs = BlendState.AlphaBlend; } else if (blendFunc.Source == OGLES.GL_SRC_ALPHA && blendFunc.Destination == OGLES.GL_ONE) { bs = BlendState.Additive; } else if (blendFunc.Source == OGLES.GL_SRC_ALPHA && blendFunc.Destination == OGLES.GL_ONE_MINUS_SRC_ALPHA) { bs = BlendState.NonPremultiplied; } else if (blendFunc.Source == OGLES.GL_ONE && blendFunc.Destination == OGLES.GL_ZERO) { bs = BlendState.Opaque; } else { if (!m_blendStates.TryGetValue(blendFunc, out bs)) { bs = new BlendState(); bs.ColorSourceBlend = OGLES.GetXNABlend(blendFunc.Source); bs.AlphaSourceBlend = OGLES.GetXNABlend(blendFunc.Source); bs.ColorDestinationBlend = OGLES.GetXNABlend(blendFunc.Destination); bs.AlphaDestinationBlend = OGLES.GetXNABlend(blendFunc.Destination); m_blendStates.Add(blendFunc, bs); } } graphicsDevice.BlendState = bs; m_currBlend.Source = blendFunc.Source; m_currBlend.Destination = blendFunc.Destination; //} }
public bool InitWithTexture(CCTexture2D pTexture, CCRect rect, bool rotated) { base.Init(); m_pobBatchNode = null; // shader program //setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); m_bRecursiveDirty = false; Dirty = false; m_bOpacityModifyRGB = true; m_sBlendFunc = CCBlendFunc.AlphaBlend; m_bFlipX = m_bFlipY = false; // default transform anchor: center AnchorPoint = new CCPoint(0.5f, 0.5f); // zwoptex default values m_obOffsetPosition = CCPoint.Zero; m_bHasChildren = false; // clean the Quad m_sQuad = new CCV3F_C4B_T2F_Quad(); // Atlas: Color var tmpColor = new CCColor4B(255, 255, 255, 255); m_sQuad.BottomLeft.Colors = tmpColor; m_sQuad.BottomRight.Colors = tmpColor; m_sQuad.TopLeft.Colors = tmpColor; m_sQuad.TopRight.Colors = tmpColor; // update texture (calls updateBlendFunc) Texture = pTexture; SetTextureRect(rect, rotated, rect.Size); // by default use "Self Render". // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render" BatchNode = null; return(true); }
protected void UpdateBlendFunc() { Debug.Assert(m_pobBatchNode == null, "CCSprite: updateBlendFunc doesn't work when the sprite is rendered using a CCSpriteSheet"); // it's possible to have an untextured sprite if (m_pobTexture == null || !m_pobTexture.HasPremultipliedAlpha) { m_sBlendFunc = CCBlendFunc.NonPremultiplied; IsOpacityModifyRGB = false; } else { m_sBlendFunc = CCBlendFunc.AlphaBlend; IsOpacityModifyRGB = true; } }
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 virtual bool InitWithTotalParticles(int numberOfParticles) { m_uTotalParticles = numberOfParticles; m_pParticles = new CCParticle[m_uTotalParticles]; m_uAllocatedParticles = numberOfParticles; if (m_pBatchNode != null) { for (int i = 0; i < m_uTotalParticles; i++) { m_pParticles[i].atlasIndex = i; } } // default, active m_bIsActive = true; // default blend function m_tBlendFunc = CCBlendFunc.AlphaBlend; // default movement type; m_ePositionType = CCPositionType.Free; // by default be in mode A: m_nEmitterMode = CCEmitterMode.Gravity; // default: modulate // XXX: not used // colorModulate = YES; m_bIsAutoRemoveOnFinish = false; // Optimization: compile udpateParticle method //updateParticleSel = @selector(updateQuadWithParticle:newPosition:); //updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel]; //for batchNode m_bTransformSystemDirty = false; return(true); }
protected virtual bool InitWithTexture(CCTexture2D tex, int capacity) { m_blendFunc = CCBlendFunc.AlphaBlend; m_pobTextureAtlas = new CCTextureAtlas(); if (capacity == 0) { capacity = kDefaultSpriteBatchCapacity; } ContentSize = tex.ContentSize; // @@ TotallyEvil - contentSize should return the size of the sprite sheet m_pobTextureAtlas.InitWithTexture(tex, capacity); UpdateBlendFunc(); // no lazy alloc in this node m_pChildren = new CCRawList <CCNode>(capacity); m_pobDescendants = new CCRawList <CCSprite>(capacity); return(true); }
public bool InitWithTexture(CCTexture2D texture, int tileWidth, int tileHeight, int itemsToRender) { m_uItemWidth = tileWidth; m_uItemHeight = tileHeight; m_tColorUnmodified = CCTypes.CCWhite; m_bIsOpacityModifyRGB = true; m_tBlendFunc = CCBlendFunc.AlphaBlend; m_pTextureAtlas = new CCTextureAtlas(); m_pTextureAtlas.InitWithTexture(texture, itemsToRender); UpdateBlendFunc(); UpdateOpacityModifyRgb(); CalculateMaxItems(); m_uQuadsToDraw = itemsToRender; return(true); }
// override addChild: public override void AddChild(CCNode child, int zOrder, int tag) { Debug.Assert(child != null, "Argument must be non-null"); Debug.Assert(child is CCParticleSystem, "CCParticleBatchNode only supports CCQuadParticleSystems as children"); var pChild = (CCParticleSystem)child; Debug.Assert(pChild.Texture.Name == TextureAtlas.Texture.Name, "CCParticleSystem is not using the same texture id"); // If this is the 1st children, then copy blending function if (m_pChildren.Count == 0) { BlendFunc = pChild.BlendFunc; } Debug.Assert(m_tBlendFunc.Source == pChild.BlendFunc.Source && m_tBlendFunc.Destination == pChild.BlendFunc.Destination, "Can't add a PaticleSystem that uses a differnt blending function"); //no lazy sorting, so don't call super addChild, call helper instead int pos = AddChildHelper(pChild, zOrder, tag); //get new atlasIndex int atlasIndex; if (pos != 0) { var p = (CCParticleSystem)m_pChildren[pos - 1]; atlasIndex = p.AtlasIndex + p.TotalParticles; } else { atlasIndex = 0; } InsertChild(pChild, atlasIndex); // update quad info pChild.BatchNode = this; }
private void updateBlendFunc() { Debug.Assert(m_pBatchNode == null, "Can't change blending functions when the particle is being batched"); if (m_pTexture != null) { bool premultiplied = m_pTexture.HasPremultipliedAlpha; m_bOpacityModifyRGB = false; if (m_tBlendFunc == CCBlendFunc.AlphaBlend) { if (premultiplied) { m_bOpacityModifyRGB = true; } else { m_tBlendFunc = CCBlendFunc.NonPremultiplied; } } } }
protected virtual bool InitWithTexture(CCTexture2D tex, int capacity) { m_blendFunc = CCBlendFunc.AlphaBlend; m_pobTextureAtlas = new CCTextureAtlas(); if (capacity == 0) { capacity = kDefaultSpriteBatchCapacity; } ContentSize= tex.ContentSize; // @@ TotallyEvil - contentSize should return the size of the sprite sheet m_pobTextureAtlas.InitWithTexture(tex, capacity); UpdateBlendFunc(); // no lazy alloc in this node m_pChildren = new CCRawList<CCNode>(capacity); m_pobDescendants = new CCRawList<CCSprite>(capacity); return true; }
/// <summary> /// initializes a CCLayer with color, width and height in Points /// </summary> public virtual bool InitWithColor(CCColor4B color, float width, float height) { base.Init(); // default blend function m_tBlendFunc = CCBlendFunc.NonPremultiplied; _displayedColor.R = _realColor.R = color.R; _displayedColor.G = _realColor.G = color.G; _displayedColor.B = _realColor.B = color.B; _displayedOpacity = _realOpacity = color.A; for (int i = 0; i < m_pSquareVertices.Length; i++) { m_pSquareVertices[i].Position.X = 0.0f; m_pSquareVertices[i].Position.Y = 0.0f; } UpdateColor(); ContentSize = new CCSize(width, height); return(true); }
protected virtual void OnHandlePropTypeBlendFunc(CCNode node, CCNode parent, string propertyName, CCBlendFunc blendFunc, CCBReader reader) { CCLog.Log("Unexpected property type: '{0}'!", propertyName); Debug.Assert(false); }
public bool InitWithTexture(CCTexture2D pTexture, CCRect rect, bool rotated) { base.Init(); m_pobBatchNode = null; // shader program //setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); m_bRecursiveDirty = false; Dirty = false; m_bOpacityModifyRGB = true; m_sBlendFunc = CCBlendFunc.AlphaBlend; m_bFlipX = m_bFlipY = false; // default transform anchor: center AnchorPoint = new CCPoint(0.5f, 0.5f); // zwoptex default values m_obOffsetPosition = CCPoint.Zero; m_bHasChildren = false; // clean the Quad m_sQuad = new CCV3F_C4B_T2F_Quad(); // Atlas: Color var tmpColor = new CCColor4B(255, 255, 255, 255); m_sQuad.BottomLeft.Colors = tmpColor; m_sQuad.BottomRight.Colors = tmpColor; m_sQuad.TopLeft.Colors = tmpColor; m_sQuad.TopRight.Colors = tmpColor; // update texture (calls updateBlendFunc) Texture = pTexture; SetTextureRect(rect, rotated, rect.Size); // by default use "Self Render". // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render" BatchNode = null; return true; }
public virtual void ParseProperties(CCNode node, CCNode parent, CCBReader reader) { int numRegularProps = reader.ReadInt(false); int numExturaProps = reader.ReadInt(false); int propertyCount = numRegularProps + numExturaProps; for (int i = 0; i < propertyCount; i++) { bool isExtraProp = (i >= numRegularProps); int type = reader.ReadInt(false); string propertyName = reader.ReadCachedString(); // Check if the property can be set for this platform bool setProp = false; var platform = (CCBPlatform)reader.ReadByte(); if (platform == CCBPlatform.All) { setProp = true; } #if __CC_PLATFORM_IOS if (platform == kCCBPlatform.kCCBPlatformIOS) { setProp = true; } #elif __CC_PLATFORM_MAC if (platform == kCCBPlatform.kCCBPlatformMac) { setProp = true; } #endif // Forward properties for sub ccb files if (node is CCBFile) { var ccbNode = (CCBFile)node; if (ccbNode.FileNode != null && isExtraProp) { node = ccbNode.FileNode; // Skip properties that doesn't have a value to override var extraPropsNames = (List <string>)node.UserObject; setProp &= extraPropsNames.Contains(propertyName); } } else if (isExtraProp && node == reader.AnimationManager.RootNode) { var extraPropsNames = (List <string>)node.UserObject; if (extraPropsNames == null) { extraPropsNames = new List <string>(); node.UserObject = extraPropsNames; } extraPropsNames.Add(propertyName); } switch ((CCBPropType)type) { case CCBPropType.Position: { CCPoint position = ParsePropTypePosition(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypePosition(node, parent, propertyName, position, reader); } break; } case CCBPropType.Point: { CCPoint point = ParsePropTypePoint(node, parent, reader); if (setProp) { OnHandlePropTypePoint(node, parent, propertyName, point, reader); } break; } case CCBPropType.PointLock: { CCPoint pointLock = ParsePropTypePointLock(node, parent, reader); if (setProp) { OnHandlePropTypePointLock(node, parent, propertyName, pointLock, reader); } break; } case CCBPropType.Size: { CCSize size = ParsePropTypeSize(node, parent, reader); if (setProp) { OnHandlePropTypeSize(node, parent, propertyName, size, reader); } break; } case CCBPropType.ScaleLock: { float[] scaleLock = ParsePropTypeScaleLock(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeScaleLock(node, parent, propertyName, scaleLock, reader); } break; } case CCBPropType.Float: { float f = ParsePropTypeFloat(node, parent, reader); if (setProp) { OnHandlePropTypeFloat(node, parent, propertyName, f, reader); } break; } case CCBPropType.Degrees: { float degrees = ParsePropTypeDegrees(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeDegrees(node, parent, propertyName, degrees, reader); } break; } case CCBPropType.FloatScale: { float floatScale = ParsePropTypeFloatScale(node, parent, reader); if (setProp) { OnHandlePropTypeFloatScale(node, parent, propertyName, floatScale, reader); } break; } case CCBPropType.Integer: { int integer = ParsePropTypeInteger(node, parent, reader); if (setProp) { OnHandlePropTypeInteger(node, parent, propertyName, integer, reader); } break; } case CCBPropType.IntegerLabeled: { int integerLabeled = ParsePropTypeIntegerLabeled(node, parent, reader); if (setProp) { OnHandlePropTypeIntegerLabeled(node, parent, propertyName, integerLabeled, reader); } break; } case CCBPropType.FloatVar: { float[] floatVar = ParsePropTypeFloatVar(node, parent, reader); if (setProp) { OnHandlePropTypeFloatVar(node, parent, propertyName, floatVar, reader); } break; } case CCBPropType.Check: { bool check = ParsePropTypeCheck(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeCheck(node, parent, propertyName, check, reader); } break; } case CCBPropType.SpriteFrame: { CCSpriteFrame ccSpriteFrame = ParsePropTypeSpriteFrame(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeSpriteFrame(node, parent, propertyName, ccSpriteFrame, reader); } break; } case CCBPropType.Animation: { CCAnimation ccAnimation = ParsePropTypeAnimation(node, parent, reader); if (setProp) { OnHandlePropTypeAnimation(node, parent, propertyName, ccAnimation, reader); } break; } case CCBPropType.Texture: { CCTexture2D ccTexture2D = ParsePropTypeTexture(node, parent, reader); if (setProp) { OnHandlePropTypeTexture(node, parent, propertyName, ccTexture2D, reader); } break; } case CCBPropType.Byte: { byte b = ParsePropTypeByte(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeByte(node, parent, propertyName, b, reader); } break; } case CCBPropType.Color3: { CCColor3B color3B = ParsePropTypeColor3(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeColor3(node, parent, propertyName, color3B, reader); } break; } case CCBPropType.Color4FVar: { CCColor4F[] color4FVar = ParsePropTypeColor4FVar(node, parent, reader); if (setProp) { OnHandlePropTypeColor4FVar(node, parent, propertyName, color4FVar, reader); } break; } case CCBPropType.Flip: { bool[] flip = ParsePropTypeFlip(node, parent, reader); if (setProp) { OnHandlePropTypeFlip(node, parent, propertyName, flip, reader); } break; } case CCBPropType.Blendmode: { CCBlendFunc blendFunc = ParsePropTypeBlendFunc(node, parent, reader); if (setProp) { OnHandlePropTypeBlendFunc(node, parent, propertyName, blendFunc, reader); } break; } case CCBPropType.FntFile: { string fntFile = ParsePropTypeFntFile(node, parent, reader); if (setProp) { OnHandlePropTypeFntFile(node, parent, propertyName, fntFile, reader); } break; } case CCBPropType.FontTTF: { string fontTTF = ParsePropTypeFontTTF(node, parent, reader); if (setProp) { OnHandlePropTypeFontTTF(node, parent, propertyName, fontTTF, reader); } break; } case CCBPropType.String: { string s = ParsePropTypeString(node, parent, reader); if (setProp) { OnHandlePropTypeString(node, parent, propertyName, s, reader); } break; } case CCBPropType.Text: { string text = ParsePropTypeText(node, parent, reader); if (setProp) { OnHandlePropTypeText(node, parent, propertyName, text, reader); } break; } case CCBPropType.Block: { BlockData blockData = ParsePropTypeBlock(node, parent, reader); if (setProp) { OnHandlePropTypeBlock(node, parent, propertyName, blockData, reader); } break; } case CCBPropType.BlockCCControl: { BlockCCControlData blockCCControlData = ParsePropTypeBlockCcControl(node, parent, reader); if (setProp && blockCCControlData != null) { OnHandlePropTypeBlockCcControl(node, parent, propertyName, blockCCControlData, reader); } break; } case CCBPropType.CCBFile: { CCNode ccbFileNode = ParsePropTypeCcbFile(node, parent, reader); if (setProp) { OnHandlePropTypeCCBFile(node, parent, propertyName, ccbFileNode, reader); } break; } default: //ASSERT_FAIL_UNEXPECTED_PROPERTYTYPE(type); break; } } }
public virtual bool InitWithTotalParticles(int numberOfParticles) { m_uTotalParticles = numberOfParticles; m_pParticles = new CCParticle[m_uTotalParticles]; m_uAllocatedParticles = numberOfParticles; if (m_pBatchNode != null) { for (int i = 0; i < m_uTotalParticles; i++) { m_pParticles[i].atlasIndex = i; } } // default, active m_bIsActive = true; // default blend function m_tBlendFunc = CCBlendFunc.AlphaBlend; // default movement type; m_ePositionType = CCPositionType.Free; // by default be in mode A: m_nEmitterMode = CCEmitterMode.Gravity; // default: modulate // XXX: not used // colorModulate = YES; m_bIsAutoRemoveOnFinish = false; // Optimization: compile udpateParticle method //updateParticleSel = @selector(updateQuadWithParticle:newPosition:); //updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel]; //for batchNode m_bTransformSystemDirty = false; return true; }
public override void OnEnter() { base.OnEnter(); Color = CCTypes.CCBlack; RemoveChild(m_background, true); m_background = null; m_emitter = new CCParticleSystemQuad("Particles/BoilingFoam"); // Particle Designer "normal" blend func causes black halo on premul textures (ignores multiplication) //this->emitter.blendFunc = (ccBlendFunc){ GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }; // Cocos2d "normal" blend func for premul causes alpha to be ignored (oversaturates colors) var tBlendFunc = new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE_MINUS_SRC_ALPHA); m_emitter.BlendFunc = tBlendFunc; //Debug.Assert(m_emitter.OpacityModifyRGB, "Particle texture does not have premultiplied alpha, test is useless"); // Toggle next line to see old behavior // this->emitter.opacityModifyRGB = NO; m_emitter.StartColor = new CCColor4F(1, 1, 1, 1); m_emitter.EndColor = new CCColor4F(1, 1, 1, 0); m_emitter.StartColorVar = new CCColor4F(0, 0, 0, 0); m_emitter.EndColorVar = new CCColor4F(0, 0, 0, 0); AddChild(m_emitter, 10); }
/// <summary> /// initializes a CCLayer with color, width and height in Points /// </summary> public virtual bool InitWithColor(CCColor4B color, float width, float height) { base.Init(); // default blend function m_tBlendFunc = CCBlendFunc.NonPremultiplied; _displayedColor.R = _realColor.R = color.R; _displayedColor.G = _realColor.G = color.G; _displayedColor.B = _realColor.B = color.B; _displayedOpacity = _realOpacity = color.A; for (int i = 0; i < m_pSquareVertices.Length; i++) { m_pSquareVertices[i].Position.X = 0.0f; m_pSquareVertices[i].Position.Y = 0.0f; } UpdateColor(); ContentSize = new CCSize(width, height); return true; }
public bool InitWithTexture(CCTexture2D texture, int tileWidth, int tileHeight, int itemsToRender) { m_uItemWidth = tileWidth; m_uItemHeight = tileHeight; m_tColorUnmodified = CCTypes.CCWhite; m_bIsOpacityModifyRGB = true; m_tBlendFunc = CCBlendFunc.AlphaBlend; m_pTextureAtlas = new CCTextureAtlas(); m_pTextureAtlas.InitWithTexture(texture, itemsToRender); UpdateBlendFunc(); UpdateOpacityModifyRgb(); CalculateMaxItems(); m_uQuadsToDraw = itemsToRender; return true; }
// override addChild: public override void AddChild(CCNode child, int zOrder, int tag) { Debug.Assert(child != null, "Argument must be non-null"); Debug.Assert(child is CCParticleSystem, "CCParticleBatchNode only supports CCQuadParticleSystems as children"); var pChild = (CCParticleSystem) child; Debug.Assert(pChild.Texture.Name == TextureAtlas.Texture.Name, "CCParticleSystem is not using the same texture id"); // If this is the 1st children, then copy blending function if (m_pChildren.Count == 0) { BlendFunc = pChild.BlendFunc; } Debug.Assert(m_tBlendFunc.Source == pChild.BlendFunc.Source && m_tBlendFunc.Destination == pChild.BlendFunc.Destination, "Can't add a PaticleSystem that uses a differnt blending function"); //no lazy sorting, so don't call super addChild, call helper instead int pos = AddChildHelper(pChild, zOrder, tag); //get new atlasIndex int atlasIndex; if (pos != 0) { var p = (CCParticleSystem) m_pChildren[pos - 1]; atlasIndex = p.AtlasIndex + p.TotalParticles; } else { atlasIndex = 0; } InsertChild(pChild, atlasIndex, tag); // update quad info pChild.BatchNode = this; }
/** Pointers */ public CCMotionStreak() { m_tBlendFunc = CCBlendFunc.NonPremultiplied; }
/** Pointers */ public CCMotionStreak() { m_tBlendFunc = new CCBlendFunc(CCOGLES.GL_SRC_ALPHA, CCOGLES.GL_ONE_MINUS_SRC_ALPHA); }
public bool InitWithFade(float fade, float minSeg, float stroke, CCColor3B color, CCTexture2D texture) { Position = CCPoint.Zero; AnchorPoint = CCPoint.Zero; IgnoreAnchorPointForPosition = true; m_bStartingPositionInitialized = false; m_tPositionR = CCPoint.Zero; m_bFastMode = true; m_fMinSeg = (minSeg == -1.0f) ? stroke / 5.0f : minSeg; m_fMinSeg *= m_fMinSeg; m_fStroke = stroke; m_fFadeDelta = 1.0f / fade; m_uMaxPoints = (int) (fade * 60.0f) + 2; m_uNuPoints = 0; m_pPointState = new float[m_uMaxPoints]; m_pPointVertexes = new CCPoint[m_uMaxPoints]; m_pVertices = new CCV3F_C4B_T2F[(m_uMaxPoints + 1) * 2]; // Set blend mode m_tBlendFunc = CCBlendFunc.NonPremultiplied; Texture = texture; Color = color; ScheduleUpdate(); return true; }
// CCParticleBatchNode - CocosNodeTexture protocol private void UpdateBlendFunc() { if (!TextureAtlas.Texture.HasPremultipliedAlpha) { m_tBlendFunc = CCBlendFunc.NonPremultiplied; } }
/** Pointers */ public CCMotionStreak() { m_tBlendFunc = new CCBlendFunc(OGLES.GL_SRC_ALPHA, OGLES.GL_ONE_MINUS_SRC_ALPHA); }
public void initialize() { atlas = null; debugSlots = false; debugBones = false; timeScale = 1; blendFunc = new CCBlendFunc(CCOGLES.GL_ONE, CCOGLES.GL_ONE_MINUS_SRC_ALPHA); CCDrawManager.BlendFunc(blendFunc); setOpacityModifyRGB(true); //SetShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor)); ScheduleUpdate(); }