public AnimationCache() { var frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; frameCache.AddSpriteFramesWithFile("animations/grossini.plist"); frameCache.AddSpriteFramesWithFile("animations/grossini_gray.plist"); frameCache.AddSpriteFramesWithFile("animations/grossini_blue.plist"); // // create animation "dance" // var animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { str = string.Format("grossini_dance_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance"); // // create animation "dance gray" // animFrames.Clear(); for (int i = 1; i < 15; i++) { str = String.Format("grossini_dance_gray_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str); animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_gray"); // // create animation "dance blue" // animFrames.Clear(); for (int i = 1; i < 4; i++) { str = String.Format("grossini_blue_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str); animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_blue"); CCAnimationCache animCache = CCAnimationCache.SharedAnimationCache; CCAnimation normal = animCache.AnimationByName("dance"); normal.RestoreOriginalFrame = true; CCAnimation dance_grey = animCache.AnimationByName("dance_gray"); dance_grey.RestoreOriginalFrame = true; CCAnimation dance_blue = animCache.AnimationByName("dance_blue"); dance_blue.RestoreOriginalFrame = true; CCAnimate animN = new CCAnimate(normal); CCAnimate animG = new CCAnimate(dance_grey); CCAnimate animB = new CCAnimate(dance_blue); CCFiniteTimeAction seq = CCSequence.FromActions(animN, animG, animB); // create an sprite without texture CCSprite grossini = new CCSprite(); grossini.DisplayFrame = frameCache.SpriteFrameByName("grossini_dance_01.png"); CCSize winSize = CCDirector.SharedDirector.WinSize; grossini.Position = (new CCPoint(winSize.Width / 2, winSize.Height / 2)); AddChild(grossini); // run the animation grossini.RunAction(seq); }
public static void PurgeSharedAnimationCache() { s_pSharedAnimationCache = null; }
public AnimationCache() { var frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; frameCache.AddSpriteFrames("animations/grossini.plist"); frameCache.AddSpriteFrames("animations/grossini_gray.plist"); frameCache.AddSpriteFrames("animations/grossini_blue.plist"); // // create animation "dance" // var animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { str = string.Format("grossini_dance_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache[str]; animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance"); // // create animation "dance gray" // animFrames.Clear(); for (int i = 1; i < 15; i++) { str = String.Format("grossini_dance_gray_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache[str]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_gray"); // // create animation "dance blue" // animFrames.Clear(); for (int i = 1; i < 4; i++) { str = String.Format("grossini_blue_{0:00}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache[str]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.SharedAnimationCache.AddAnimation(animation, "dance_blue"); CCAnimationCache animCache = CCAnimationCache.SharedAnimationCache; CCAnimation normal = animCache["dance"]; normal.RestoreOriginalFrame = true; CCAnimation dance_grey = animCache["dance_gray"]; dance_grey.RestoreOriginalFrame = true; CCAnimation dance_blue = animCache["dance_blue"]; dance_blue.RestoreOriginalFrame = true; CCAnimate animN = new CCAnimate(normal); CCAnimate animG = new CCAnimate(dance_grey); CCAnimate animB = new CCAnimate(dance_blue); seqAnimation = new CCSequence(animN, animG, animB); grossini = new CCSprite(); AddChild(grossini); }
public AnimationCache() { CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini"); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_gray"); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_blue"); // // create animation "dance" // List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { string temp = ""; if (i < 10) { temp = "0" + i; } else { temp = i.ToString(); } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = CCAnimation.animationWithFrames(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance"); // // create animation "dance gray" // animFrames.Clear(); for (int i = 1; i < 15; i++) { string temp = ""; if (i < 10) { temp = "0" + i; } else { temp = i.ToString(); } str = String.Format("grossini_dance_gray_{0}.png", temp); CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str); animFrames.Add(frame); } animation = CCAnimation.animationWithFrames(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance_gray"); // // create animation "dance blue" // animFrames.Clear(); for (int i = 1; i < 4; i++) { str = String.Format("grossini_blue_0{0}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str); animFrames.Add(frame); } animation = CCAnimation.animationWithFrames(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance_blue"); CCAnimationCache animCache = CCAnimationCache.sharedAnimationCache(); CCAnimation normal = animCache.animationByName("dance"); CCAnimation dance_grey = animCache.animationByName("dance_gray"); CCAnimation dance_blue = animCache.animationByName("dance_blue"); CCAnimate animN = CCAnimate.actionWithAnimation(normal); CCAnimate animG = CCAnimate.actionWithAnimation(dance_grey); CCAnimate animB = CCAnimate.actionWithAnimation(dance_blue); CCFiniteTimeAction seq = CCSequence.actions(animN, animG, animB); // create an sprite without texture CCSprite grossini = new CCSprite(); grossini.init(); CCSize winSize = CCDirector.sharedDirector().getWinSize(); grossini.position = (new CCPoint(winSize.width / 2, winSize.height / 2)); addChild(grossini); // run the animation grossini.runAction(seq); }