public override void RemoveChild(CCNode child, bool cleanup) { if (child == null) { return; } Debug.Assert(child is CCParticleSystem, "CCParticleBatchNode only supports CCQuadParticleSystems as children"); Debug.Assert(Children.Contains(child), "CCParticleBatchNode doesn't contain the sprite. Can't remove it"); CCParticleSystem pChild = (CCParticleSystem)child; // remove child helper TextureAtlas.RemoveQuadsAtIndex(pChild.AtlasIndex, pChild.TotalParticles); // after memmove of data, empty the quads at the end of array TextureAtlas.FillWithEmptyQuadsFromIndex(TextureAtlas.TotalQuads, pChild.TotalParticles); // particle could be reused for self rendering pChild.BatchNode = null; // Need to remove child from list of children before we update atlas indices base.RemoveChild(pChild, cleanup); UpdateAllAtlasIndexes(); }
// don't use lazy sorting, reordering the particle systems quads afterwards would be too complex // XXX research whether lazy sorting + freeing current quads and calloc a new block with size of capacity would be faster // XXX or possibly using vertexZ for reordering, that would be fastest // this helper is almost equivalent to CCNode's addChild, but doesn't make use of the lazy sorting int AddChildHelper(CCParticleSystem child, int z, int aTag) { Debug.Assert(child != null, "Argument must be non-nil"); Debug.Assert(child.Parent == null, "child already added. It can't be added again"); if (Children == null) { Children = new CCRawList <CCNode>(4); } // Don't use a lazy insert int pos = SearchNewPositionInChildrenForZ(z); Children.Insert(pos, child); child.Parent = this; child.Tag = aTag; child.ZOrder = z; if (IsRunning) { child.OnEnter(); child.OnEnterTransitionDidFinish(); } return(pos); }
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"); CCParticleSystem pChild = (CCParticleSystem)child; Debug.Assert(pChild.Texture.Name == TextureAtlas.Texture.Name, "CCParticleSystem is not using the same texture id"); // If this is the 1st child, then copy blending function if (Children.Count == 0) { BlendFunc = pChild.BlendFunc; } Debug.Assert(BlendFunc.Source == pChild.BlendFunc.Source && BlendFunc.Destination == pChild.BlendFunc.Destination, "Can't add a ParticleSystem that uses a differnt blending function"); // Set layer before we call AddChildHelper if (Layer != null) { pChild.Layer = Layer; } // No lazy sorting, so don't call base AddChild, call helper instead int pos = AddChildHelper(pChild, zOrder, tag); int atlasIndex; if (pos != 0) { CCParticleSystem p = (CCParticleSystem)Children[pos - 1]; atlasIndex = p.AtlasIndex + p.TotalParticles; } else { atlasIndex = 0; } InsertChild(pChild, atlasIndex, tag); pChild.BatchNode = this; }
protected override void AddedToScene() { base.AddedToScene (); CCRect visibleBounds = VisibleBoundsWorldspace; CCPoint centerBounds = visibleBounds.Center; CCPoint quarterWidthDelta = new CCPoint (visibleBounds.Size.Width / 4.0f, 0.0f); // Layout the positioning of sprites based on visibleBounds monkeySprite1.AnchorPoint = CCPoint.AnchorMiddle; monkeySprite1.Position = centerBounds + quarterWidthDelta; monkeySprite2.AnchorPoint = CCPoint.AnchorMiddle; monkeySprite2.Position = centerBounds - quarterWidthDelta; // Run actions on sprite // Note: we can reuse the same action definition on multiple sprites! monkeySprite1.RunAction (new CCSequence (dreamAction, repeatedAction)); monkeySprite2.RunAction (new CCSequence (dreamAction, new CCDelayTime (0.5f), repeatedAction)); // Create preloaded galaxy particle system galaxySystem = new CCParticleGalaxy (centerBounds); // Customise default behaviour of predefined particle system galaxySystem.EmissionRate = 20.0f; galaxySystem.EndSize = 3.0f; galaxySystem.EndRadius = visibleBounds.Size.Width; galaxySystem.Life = 10.0f; AddChild (galaxySystem, 0); // Register to touch event var touchListener = new CCEventListenerTouchAllAtOnce (); touchListener.OnTouchesEnded = OnTouchesEnded; AddEventListener (touchListener, this); }
void InsertChild(CCParticleSystem pSystem, int index, int tag) { pSystem.AtlasIndex = index; if (TextureAtlas.TotalQuads + pSystem.TotalParticles > TextureAtlas.Capacity) { IncreaseAtlasCapacityTo(TextureAtlas.TotalQuads + pSystem.TotalParticles); // after a realloc empty quads of textureAtlas can be filled with gibberish (realloc doesn't perform calloc), insert empty quads to prevent it TextureAtlas.FillWithEmptyQuadsFromIndex(TextureAtlas.Capacity - pSystem.TotalParticles, pSystem.TotalParticles); } // make room for quads, not necessary for last child if (pSystem.AtlasIndex + pSystem.TotalParticles != TextureAtlas.TotalQuads) { TextureAtlas.MoveQuadsFromIndex(index, index + pSystem.TotalParticles); } // increase totalParticles here for new particles, update method of particlesystem will fill the quads TextureAtlas.IncreaseTotalQuadsWith(pSystem.TotalParticles); UpdateAllAtlasIndexes(); }
void SetUpParticleSystemSun() { //recommended for iPad only system = new CCParticleSun(new CCPoint(240, 400)); // AddChild(system, Constants.depthParticles); system.Scale = 3; particleSystemStartPosition = system.Position; }
// don't use lazy sorting, reordering the particle systems quads afterwards would be too complex // XXX research whether lazy sorting + freeing current quads and calloc a new block with size of capacity would be faster // XXX or possibly using vertexZ for reordering, that would be fastest // this helper is almost equivalent to CCNode's addChild, but doesn't make use of the lazy sorting int AddChildHelper(CCParticleSystem child, int z, int aTag) { Debug.Assert(child != null, "Argument must be non-nil"); Debug.Assert(child.Parent == null, "child already added. It can't be added again"); if (Children == null) { Children = new CCRawList<CCNode>(4); } // Don't use a lazy insert int pos = SearchNewPositionInChildrenForZ(z); Children.Insert(pos, child); child.Parent = this; child.Tag = aTag; child.ZOrder = z; if (IsRunning) { child.OnEnter(); child.OnEnterTransitionDidFinish(); } return pos; }
public void createParticles() { _jet = new CCParticleSystemQuad("jet.plist"); _jet.SourcePosition = new CCPoint(-_rocket._radius * 0.8f, 0); _jet.Angle = 180; _jet.StopSystem(); AddChild(_jet, kBackground); _boom = new CCParticleSystemQuad("boom.plist"); _boom.StopSystem(); AddChild(_boom, kForeground); _comet = new CCParticleSystemQuad("comet.plist"); _comet.StopSystem(); _comet.Position = new CCPoint(0, _screenSize.Height * 0.6f); _comet.Visible = false; AddChild(_comet, kForeground); _pickup = new CCParticleSystemQuad("plink.plist"); _pickup.StopSystem(); AddChild(_pickup, kMiddleground); _warp = new CCParticleSystemQuad("warp.plist"); _warp.Position = _rocket.Position; AddChild(_warp, kBackground); _star = new CCParticleSystemQuad("star.plist"); _star.StopSystem(); _star.Visible = false; AddChild(_star, kBackground, kSpriteStar); }
public void createParticlesAsync() { isLoading = true; var label = new CCLabelTtf("Loading...", "MarkerFelt", 22); label.Position = _screenSize.Center; label.Position = new CCPoint(_screenSize.Center.X, _screenSize.Height * 0.75f); label.Visible = false; label.Name = "Loading"; AddChild(label, 10); var scale = new CCScaleBy(0.3f, 2); label.RunActions(new CCDelayTime(1.0f), new CCShow()); label.RepeatForever(scale, scale.Reverse()); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("jet.plist", (jetConfig) => { _jet = new CCParticleSystemQuad(jetConfig); _jet.SourcePosition = new CCPoint(-_rocket._radius * 0.8f, 0); _jet.Angle = 180; _jet.StopSystem(); AddChild(_jet, kBackground); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("boom.plist", (boomConfig) => { _boom = new CCParticleSystemQuad(boomConfig); _boom.StopSystem(); AddChild(_boom, kForeground); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("comet.plist", (cometConfig) => { _comet = new CCParticleSystemQuad(cometConfig); _comet.StopSystem(); _comet.Position = new CCPoint(0, _screenSize.Height * 0.6f); _comet.Visible = false; AddChild(_comet, kForeground); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("star.plist", (starConfig) => { _star = new CCParticleSystemQuad(starConfig); _star.StopSystem(); _star.Visible = false; AddChild(_star, kBackground, kSpriteStar); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("plink.plist", (plinkConfig) => { _pickup = new CCParticleSystemQuad(plinkConfig); _pickup.StopSystem(); AddChild(_pickup, kMiddleground); loadedParticleSystems++; updateLoading(); }); CCParticleSystemCache.SharedParticleSystemCache.AddParticleSystemAsync("warp.plist", (warpConfig) => { _warp = new CCParticleSystemQuad(warpConfig); _warp.Position = _rocket.Position; AddChild(_warp, kBackground); loadedParticleSystems++; updateLoading(); }); }