public SpriteOffsetAnchorRotation() { CCSize s = CCDirector.SharedDirector.WinSize; CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini.plist"); cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray"); for (int i = 0; i < 3; i++) { // // Animation using Sprite BatchNode // CCSprite sprite = new CCSprite("grossini_dance_01.png"); sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2)); CCSprite point = new CCSprite("Images/r1"); point.Scale = 0.25f; point.Position = (sprite.Position); AddChild(point, 1); switch (i) { case 0: sprite.AnchorPoint = new CCPoint(0, 0); break; case 1: sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); break; case 2: sprite.AnchorPoint = new CCPoint(1, 1); break; } point.Position = sprite.Position; var animFrames = new List <CCSpriteFrame>(14); string str = ""; for (int j = 0; j < 14; j++) { str = string.Format("grossini_dance_{0:00}.png", j + 1); CCSpriteFrame frame = cache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); sprite.RunAction(new CCRepeatForever(new CCAnimate(animation))); sprite.RunAction(new CCRepeatForever(new CCRotateBy(10, 360))); AddChild(sprite, 0); //animFrames.release(); // win32 : memory leak 2010-0415 } }
public override void OnEnter() { base.OnEnter(); CCSize s = CCDirector.SharedDirector.WinSize; // IMPORTANT: // The sprite frames will be cached AND RETAINED, and they won't be released unless you call // [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames]; // // CCSpriteFrameCache is a cache of CCSpriteFrames // CCSpriteFrames each contain a texture id and a rect (frame). CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini-aliases.plist", "animations/grossini-aliases"); // // Animation using Sprite batch // // A CCSpriteBatchNode can reference one and only one texture (one .png file) // Sprites that are contained in that texture can be instantiatied as CCSprites and then added to the CCSpriteBatchNode // All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call // If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient // // When you animate a sprite, CCAnimation changes the frame of the sprite using setDisplayFrame: (this is why the animation must be in the same texture) // When setDisplayFrame: is used in the CCAnimation it changes the frame to one specified by the CCSpriteFrames that were added to the animation, // but texture id is still the same and so the sprite is still a child of the CCSpriteBatchNode, // and therefore all the animation sprites are also drawn as part of the CCSpriteBatchNode // CCSprite sprite = new CCSprite("grossini_dance_01.png"); sprite.Position = (new CCPoint(s.Width * 0.5f, s.Height * 0.5f)); CCSpriteBatchNode spriteBatch = new CCSpriteBatchNode("animations/grossini-aliases"); spriteBatch.AddChild(sprite); AddChild(spriteBatch); var animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { // Obtain frames by alias name str = string.Format("dance_{0:00}", i); CCSpriteFrame frame = cache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); // 14 frames * 1sec = 14 seconds sprite.RunAction(new CCRepeatForever(new CCAnimate(animation))); }
public SpriteBatchNodeOffsetAnchorSkew() { CCSize s = CCDirector.SharedDirector.WinSize; for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini.plist"); cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray"); // // Animation using Sprite batch // CCSprite sprite = new CCSprite("grossini_dance_01.png"); sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2)); CCSprite point = new CCSprite("Images/r1"); point.Scale = 0.25f; point.Position = sprite.Position; AddChild(point, 200); switch (i) { case 0: sprite.AnchorPoint = new CCPoint(0, 0); break; case 1: sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); break; case 2: sprite.AnchorPoint = new CCPoint(1, 1); break; } point.Position = sprite.Position; CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini"); AddChild(spritebatch); var animFrames = new List <CCSpriteFrame>(); string tmp = ""; for (int j = 0; j < 14; j++) { string temp = ""; if (j + 1 < 10) { temp = "0" + (j + 1); } else { temp = (j + 1).ToString(); } tmp = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.SpriteFrameByName(tmp); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); sprite.RunAction(new CCRepeatForever(new CCAnimate(animation))); animFrames = null; CCSkewBy skewX = new CCSkewBy(2, 45, 0); CCActionInterval skewX_back = (CCActionInterval)skewX.Reverse(); CCSkewBy skewY = new CCSkewBy(2, 0, 45); CCActionInterval skewY_back = (CCActionInterval)skewY.Reverse(); CCFiniteTimeAction seq_skew = CCSequence.FromActions(skewX, skewX_back, skewY, skewY_back); sprite.RunAction(new CCRepeatForever((CCActionInterval)seq_skew)); spritebatch.AddChild(sprite, i); } }
public SpriteBatchNodeOffsetAnchorScale() { CCSize s = CCDirector.SharedDirector.WinSize; for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini.plist"); cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray"); // // Animation using Sprite BatchNode // CCSprite sprite = new CCSprite("grossini_dance_01.png"); sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2)); CCSprite point = new CCSprite("Images/r1"); point.Scale = 0.25f; point.Position = sprite.Position; AddChild(point, 200); switch (i) { case 0: sprite.AnchorPoint = new CCPoint(0, 0); break; case 1: sprite.AnchorPoint = new CCPoint(0.5f, 0.5f); break; case 2: sprite.AnchorPoint = new CCPoint(1, 1); break; } point.Position = sprite.Position; CCSpriteBatchNode spritesheet = new CCSpriteBatchNode("animations/grossini"); AddChild(spritesheet); var animFrames = new List <CCSpriteFrame>(14); string str = ""; for (int k = 0; k < 14; k++) { string temp = ""; if (k + 1 < 10) { temp = "0" + (k + 1); } else { temp = (k + 1).ToString(); } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); sprite.RunAction(new CCRepeatForever(new CCAnimate(animation))); CCActionInterval scale = new CCScaleBy(2, 2); CCActionInterval scale_back = (CCActionInterval)scale.Reverse(); CCActionInterval seq_scale = (CCActionInterval)(new CCSequence(scale, scale_back)); sprite.RunAction(new CCRepeatForever(seq_scale)); spritesheet.AddChild(sprite, i); //animFrames->release(); // win32 : memory leak 2010-0415 } }
public SpriteFrameTest() { CCSize s = CCDirector.SharedDirector.WinSize; // IMPORTANT: // The sprite frames will be cached AND RETAINED, and they won't be released unless you call // CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames); CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini.plist"); cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray"); cache.AddSpriteFramesWithFile("animations/grossini_blue.plist", "animations/grossini_blue"); // // Animation using Sprite BatchNode // m_pSprite1 = new CCSprite("grossini_dance_01.png"); m_pSprite1.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2)); CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini"); spritebatch.AddChild(m_pSprite1); AddChild(spritebatch); 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 = cache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); m_pSprite1.RunAction(new CCRepeatForever(new CCAnimate(animation))); // to test issue #732, uncomment the following line m_pSprite1.FlipX = false; m_pSprite1.FlipY = false; // // Animation using standard Sprite // m_pSprite2 = new CCSprite("grossini_dance_01.png"); m_pSprite2.Position = (new CCPoint(s.Width / 2 + 80, s.Height / 2)); AddChild(m_pSprite2); var moreFrames = new List <CCSpriteFrame>(20); for (int i = 1; i < 15; i++) { string temp; str = string.Format("grossini_dance_gray_{0:00}.png", i); CCSpriteFrame frame = cache.SpriteFrameByName(str); moreFrames.Add(frame); } for (int i = 1; i < 5; i++) { str = string.Format("grossini_blue_{0:00}.png", i); CCSpriteFrame frame = cache.SpriteFrameByName(str); moreFrames.Add(frame); } // append frames from another batch moreFrames.AddRange(animFrames); CCAnimation animMixed = new CCAnimation(moreFrames, 0.3f); m_pSprite2.RunAction(new CCRepeatForever(new CCAnimate(animMixed))); // to test issue #732, uncomment the following line m_pSprite2.FlipX = false; m_pSprite2.FlipY = false; Schedule(startIn05Secs, 0.5f); m_nCounter = 0; }
public SpriteOffsetAnchorFlip() { CCSize s = CCDirector.SharedDirector.WinSize; for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini.plist"); cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray"); // // Animation using Sprite batch // CCSprite sprite = new CCSprite("grossini_dance_01.png"); sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2)); CCSprite point = new CCSprite("Images/r1"); point.Scale = 0.25f; point.Position = sprite.Position; AddChild(point, 1); switch (i) { case 0: sprite.AnchorPoint = new CCPoint(0, 0); break; case 1: sprite.AnchorPoint = (new CCPoint(0.5f, 0.5f)); break; case 2: sprite.AnchorPoint = new CCPoint(1, 1); break; } point.Position = sprite.Position; var animFrames = new List <CCSpriteFrame>(); string tmp = ""; for (int j = 0; j < 14; j++) { string temp = ""; if (j + 1 < 10) { temp = "0" + (j + 1); } else { temp = (j + 1).ToString(); } tmp = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.SpriteFrameByName(tmp); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); sprite.RunAction(new CCRepeatForever(new CCAnimate(animation))); animFrames = null; CCFlipY flip = new CCFlipY(true); CCFlipY flip_back = new CCFlipY(false); CCDelayTime delay = new CCDelayTime(1); CCFiniteTimeAction seq = new CCSequence((CCFiniteTimeAction)delay, (CCFiniteTimeAction)flip, (CCFiniteTimeAction)delay.Copy(null), flip_back); sprite.RunAction(new CCRepeatForever((CCActionInterval)seq)); AddChild(sprite, 0); } }