public SpriteHybrid() { CCSize s = CCDirector.SharedDirector.WinSize; // parents CCNode parent1 = new CCNode(); CCSpriteBatchNode parent2 = new CCSpriteBatchNode("animations/grossini", 50); AddChild(parent1, 0, (int)kTags.kTagNode); AddChild(parent2, 0, (int)kTags.kTagSpriteBatchNode); // IMPORTANT: // The sprite frames will be cached AND RETAINED, and they won't be released unless you call // CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames); CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist"); // create 250 sprites // only show 80% of them for (int i = 0; i < 250; i++) { int spriteIdx = (int)(Random.NextDouble() * 14); string str = ""; string temp = ""; if (spriteIdx + 1 < 10) { temp = "0" + (spriteIdx + 1); } else { temp = (spriteIdx + 1).ToString(); } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str); CCSprite sprite = new CCSprite(frame); parent1.AddChild(sprite, i, i); float x = -1000; float y = -1000; if (Random.NextDouble() < 0.2f) { x = (float)(Random.NextDouble() * s.Width); y = (float)(Random.NextDouble() * s.Height); } sprite.Position = (new CCPoint(x, y)); CCActionInterval action = new CCRotateBy(4, 360); sprite.RunAction(new CCRepeatForever(action)); } m_usingSpriteBatchNode = false; Schedule(reparentSprite, 2); }
public void addNewSprite() { CCSize s = CCDirector.SharedDirector.WinSize; CCPoint p = new CCPoint((float)(Random.NextDouble() * s.Width), (float)(Random.NextDouble() * s.Height)); CCSpriteBatchNode batch = (CCSpriteBatchNode)GetChildByTag((int)kTags.kTagSpriteBatchNode); int idx = (int)(Random.NextDouble() * 1400 / 100); int x = (idx % 5) * 85; int y = (idx / 5) * 121; CCSprite sprite = new CCSprite(batch.Texture, new CCRect(x, y, 85, 121)); batch.AddChild(sprite); sprite.Position = (new CCPoint(p.X, p.Y)); CCActionInterval action; float random = (float)Random.NextDouble(); if (random < 0.20) { action = new CCScaleBy(3, 2); } else if (random < 0.40) { action = new CCRotateBy(3, 360); } else if (random < 0.60) { action = new CCBlink(1, 3); } else if (random < 0.8) { action = new CCTintBy(2, 0, -255, -255); } else { action = new CCFadeOut(2); } CCActionInterval action_back = (CCActionInterval)action.Reverse(); CCActionInterval seq = (CCActionInterval)(CCSequence.FromActions(action, action_back)); sprite.RunAction(new CCRepeatForever(seq)); }