public SpriteHybrid() { CCSize s = CCDirector.sharedDirector().getWinSize(); // parents CCNode parent1 = CCNode.node(); CCSpriteBatchNode parent2 = CCSpriteBatchNode.batchNodeWithFile("animations/images/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"); // create 250 sprites // only show 80% of them for (int i = 0; i < 250; i++) { int spriteIdx = (int)(rand.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 = CCSprite.spriteWithSpriteFrame(frame); parent1.addChild(sprite, i, i); float x = -1000; float y = -1000; if (rand.NextDouble() < 0.2f) { x = (float)(rand.NextDouble() * s.width); y = (float)(rand.NextDouble() * s.height); } sprite.position = (new CCPoint(x, y)); CCActionInterval action = CCRotateBy.actionWithDuration(4, 360); sprite.runAction(CCRepeatForever.actionWithAction(action)); } m_usingSpriteBatchNode = false; schedule(reparentSprite, 2); }
public SpriteAnimationSplit() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage("animations/images/dragon_animation"); // manually add frames to the frame cache CCSpriteFrame frame0 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 0, 132 * 0, 132, 132)); CCSpriteFrame frame1 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 1, 132 * 0, 132, 132)); CCSpriteFrame frame2 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 2, 132 * 0, 132, 132)); CCSpriteFrame frame3 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 3, 132 * 0, 132, 132)); CCSpriteFrame frame4 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 0, 132 * 1, 132, 132)); CCSpriteFrame frame5 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 1, 132 * 1, 132, 132)); // // Animation using Sprite BatchNode // CCSprite sprite = CCSprite.spriteWithSpriteFrame(frame0); sprite.position = (new CCPoint(s.width / 2 - 80, s.height / 2)); addChild(sprite); List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(6); animFrames.Add(frame0); animFrames.Add(frame1); animFrames.Add(frame2); animFrames.Add(frame3); animFrames.Add(frame4); animFrames.Add(frame5); CCAnimation animation = CCAnimation.animationWithFrames(animFrames, 0.2f); CCAnimate animate = CCAnimate.actionWithAnimation(animation, false); CCActionInterval seq = (CCActionInterval)(CCSequence.actions(animate, CCFlipX.actionWithFlipX(true), (CCFiniteTimeAction)animate.copy(), CCFlipX.actionWithFlipX(false) )); sprite.runAction(CCRepeatForever.actionWithAction(seq)); //animFrames->release(); // win32 : memory leak 2010-0415 }
public override void onEnter() { base.onEnter(); CCSize s = CCDirector.sharedDirector().getWinSize(); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("zwoptex/grossini"); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("zwoptex/grossini-generic"); CCLayerColor layer1 = CCLayerColor.layerWithColorWidthHeight(new ccColor4B(255, 0, 0, 255), 85, 121); layer1.position = (new CCPoint(s.width / 2 - 80 - (85.0f * 0.5f), s.height / 2 - (121.0f * 0.5f))); addChild(layer1); sprite1 = CCSprite.spriteWithSpriteFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("grossini_dance_01.png")); sprite1.position = (new CCPoint(s.width / 2 - 80, s.height / 2)); addChild(sprite1); sprite1.IsFlipX = (false); sprite1.IsFlipY = (false); CCLayerColor layer2 = CCLayerColor.layerWithColorWidthHeight(new ccColor4B(255, 0, 0, 255), 85, 121); layer2.position = (new CCPoint(s.width / 2 + 80 - (85.0f * 0.5f), s.height / 2 - (121.0f * 0.5f))); addChild(layer2); sprite2 = CCSprite.spriteWithSpriteFrame(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName("grossini_dance_generic_01.png")); sprite2.position = (new CCPoint(s.width / 2 + 80, s.height / 2)); addChild(sprite2); sprite2.IsFlipX = (false); sprite2.IsFlipY = (false); schedule((startIn05Secs), 1.0f); counter = 0; }