protected bool InitWithAnimation(CCAnimation pAnimation) { Debug.Assert(pAnimation != null); float singleDuration = pAnimation.Duration; if (base.InitWithDuration(singleDuration * pAnimation.Loops)) { m_nNextFrame = 0; m_pAnimation = pAnimation; m_pOrigFrame = null; m_uExecutedLoops = 0; m_pSplitTimes.Capacity = pAnimation.Frames.Count; float accumUnitsOfTime = 0; float newUnitOfTimeValue = singleDuration / pAnimation.TotalDelayUnits; var pFrames = pAnimation.Frames; //TODO: CCARRAY_VERIFY_TYPE(pFrames, CCAnimationFrame *); foreach (var pObj in pFrames) { var frame = (CCAnimationFrame) pObj; float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration; accumUnitsOfTime += frame.DelayUnits; m_pSplitTimes.Add(value); } return true; } return false; }
public void AddAnimation(CCAnimation animation, string name) { if (!m_pAnimations.ContainsKey(name)) { m_pAnimations.Add(name, animation); } }
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 void SetDisplayFrameWithAnimationName(string animationName, int frameIndex) { Debug.Assert(!String.IsNullOrEmpty(animationName), "CCSprite#setDisplayFrameWithAnimationName. animationName must not be NULL"); CCAnimation a = CCAnimationCache.SharedAnimationCache.AnimationByName(animationName); Debug.Assert(a != null, "CCSprite#setDisplayFrameWithAnimationName: Frame not found"); var frame = (CCAnimationFrame)a.Frames[frameIndex]; Debug.Assert(frame != null, "CCSprite#setDisplayFrame. Invalid frame"); DisplayFrame = frame.SpriteFrame; }
public object Copy(ICCCopyable pZone) { CCAnimation pCopy = null; if (pZone != null) { //in case of being called at sub class pCopy = (CCAnimation)(pZone); } else { pCopy = new CCAnimation(); } pCopy.InitWithAnimationFrames(m_pFrames, m_fDelayPerUnit, m_uLoops); pCopy.RestoreOriginalFrame = m_bRestoreOriginalFrame; return(pCopy); }
public SpriteAnimationSplit() { CCSize s = CCDirector.SharedDirector.WinSize; CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation"); // manually add frames to the frame cache CCSpriteFrame frame0 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 0, 132, 132)); CCSpriteFrame frame1 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 0, 132, 132)); CCSpriteFrame frame2 = new CCSpriteFrame(texture, new CCRect(132 * 2, 132 * 0, 132, 132)); CCSpriteFrame frame3 = new CCSpriteFrame(texture, new CCRect(132 * 3, 132 * 0, 132, 132)); CCSpriteFrame frame4 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 1, 132, 132)); CCSpriteFrame frame5 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 1, 132, 132)); // // Animation using Sprite BatchNode // CCSprite sprite = new CCSprite(frame0); sprite.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2)); AddChild(sprite); var 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 = new CCAnimation(animFrames, 0.2f); CCAnimate animate = new CCAnimate (animation); CCActionInterval seq = (CCActionInterval)(new CCSequence(animate, new CCFlipX(true), (CCFiniteTimeAction)animate.Copy(), new CCFlipX(false) )); sprite.RunAction(new CCRepeatForever (seq)); //animFrames->release(); // win32 : memory leak 2010-0415 }
protected virtual CCAnimation ParsePropTypeAnimation(CCNode node, CCNode parent, CCBReader reader) { string animationFile = reader.ReadCachedString(); string animation = reader.ReadCachedString(); CCAnimation ccAnimation = null; // Support for stripping relative file paths, since ios doesn't currently // know what to do with them, since its pulling from bundle. // Eventually this should be handled by a client side asset manager // interface which figured out what resources to load. // TODO Does this problem exist in C++? animation = CCBReader.LastPathComponent(animation); animationFile = CCBReader.LastPathComponent(animationFile); if (!String.IsNullOrEmpty(animation)) { CCAnimationCache animationCache = CCAnimationCache.SharedAnimationCache; animationCache.AddAnimationsWithFile(animationFile); ccAnimation = animationCache.AnimationByName(animation); } return(ccAnimation); }
public object Copy(ICCCopyable pZone) { CCAnimation pCopy = null; if (pZone != null) { //in case of being called at sub class pCopy = (CCAnimation) (pZone); } else { pCopy = new CCAnimation(); } pCopy.InitWithAnimationFrames(m_pFrames, m_fDelayPerUnit, m_uLoops); pCopy.RestoreOriginalFrame = m_bRestoreOriginalFrame; return pCopy; }
public CCAnimate CreateAnimateAction() { var frameList = new List<CCSpriteFrame>(); for (var i = 0; i < 7; i++) { var texture = CreateCharacterTexture(); var sprite = new CCSpriteFrame(texture, new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height)); frameList.Add(sprite); } var animation = new CCAnimation(frameList, 0.1f); var animate = new CCAnimate (animation); return animate; }
public override void OnEnter() { base.OnEnter(); centerSprites(3); // // Manual animation // var animation = new CCAnimation(); for (var i = 1; i < 15; i++) { var szName = String.Format("Images/grossini_dance_{0:00}", i); animation.AddSpriteFrameWithFileName(szName); } // should last 2.8 seconds. And there are 14 frames. animation.DelayPerUnit = 2.8f / 14.0f; animation.RestoreOriginalFrame = true; var action = new CCAnimate (animation); m_grossini.RunAction(new CCSequence(action, action.Reverse())); // // File animation // // With 2 loops and reverse var cache = CCAnimationCache.SharedAnimationCache; cache.AddAnimationsWithFile("animations/animations-2.plist"); var animation2 = cache.AnimationByName("dance_1"); var action2 = new CCAnimate (animation2); m_tamara.RunAction(new CCSequence(action2, action2.Reverse())); // TODO: // observer_ = [[NSNotificationCenter defaultCenter] addObserverForName:CCAnimationFrameDisplayedNotification object:nil queue:nil usingBlock:^(NSNotification* notification) { // // NSDictionary *userInfo = [notification userInfo]; // NSLog(@"object %@ with data %@", [notification object], userInfo ); // }]; // // File animation // // with 4 loops var animation3 = (CCAnimation) animation2.Copy(); animation3.Loops = 4; var action3 = new CCAnimate (animation3); m_kathia.RunAction(action3); }
public override CCFiniteTimeAction Reverse() { var pOldArray = m_pAnimation.Frames; var pNewArray = new List<CCAnimationFrame>(pOldArray.Count); //TODO: CCARRAY_VERIFY_TYPE(pOldArray, CCAnimationFrame*); if (pOldArray.Count > 0) { for (int i = pOldArray.Count - 1; i >= 0; i--) { var pElement = (CCAnimationFrame) pOldArray[i]; if (pElement == null) { break; } pNewArray.Add(pElement.Copy() as CCAnimationFrame); } } var newAnim = new CCAnimation(pNewArray, m_pAnimation.DelayPerUnit, m_pAnimation.Loops); newAnim.RestoreOriginalFrame = m_pAnimation.RestoreOriginalFrame; return new CCAnimate(newAnim); }
protected virtual void OnHandlePropTypeAnimation(CCNode node, CCNode parent, string propertyName, CCAnimation animation, CCBReader reader) { CCLog.Log("Unexpected property type: '{0}'!", propertyName); Debug.Assert(false); }
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 = new CCSequence(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 CCAnimate(CCAnimation pAnimation) { InitWithAnimation(pAnimation); }
public static CCAnimate CreateAnimate(string[] spriteFrmaeName, float delay, uint loops = 0) { List<CCSpriteFrame> frames = new List<CCSpriteFrame>(); for (int i = 0; i < spriteFrmaeName.Length; i++) frames.Add(Factory.CreateSpriteFrame(spriteFrmaeName[i])); CCAnimation animation = new CCAnimation(frames, delay); if (loops != 0) animation.Loops = loops; CCAnimate animate = new CCAnimate(animation); return animate; }
public virtual void ParseProperties(CCNode node, CCNode parent, CCBReader reader) { int numRegularProps = reader.ReadInt(false); int numExturaProps = reader.ReadInt(false); int propertyCount = numRegularProps + numExturaProps; for (int i = 0; i < propertyCount; i++) { bool isExtraProp = (i >= numRegularProps); int type = reader.ReadInt(false); string propertyName = reader.ReadCachedString(); // Check if the property can be set for this platform bool setProp = false; var platform = (CCBPlatform)reader.ReadByte(); if (platform == CCBPlatform.All) { setProp = true; } #if __CC_PLATFORM_IOS if (platform == kCCBPlatform.kCCBPlatformIOS) { setProp = true; } #elif __CC_PLATFORM_MAC if (platform == kCCBPlatform.kCCBPlatformMac) { setProp = true; } #endif // Forward properties for sub ccb files if (node is CCBFile) { var ccbNode = (CCBFile)node; if (ccbNode.FileNode != null && isExtraProp) { node = ccbNode.FileNode; // Skip properties that doesn't have a value to override var extraPropsNames = (List <string>)node.UserObject; setProp &= extraPropsNames.Contains(propertyName); } } else if (isExtraProp && node == reader.AnimationManager.RootNode) { var extraPropsNames = (List <string>)node.UserObject; if (extraPropsNames == null) { extraPropsNames = new List <string>(); node.UserObject = extraPropsNames; } extraPropsNames.Add(propertyName); } switch ((CCBPropType)type) { case CCBPropType.Position: { CCPoint position = ParsePropTypePosition(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypePosition(node, parent, propertyName, position, reader); } break; } case CCBPropType.Point: { CCPoint point = ParsePropTypePoint(node, parent, reader); if (setProp) { OnHandlePropTypePoint(node, parent, propertyName, point, reader); } break; } case CCBPropType.PointLock: { CCPoint pointLock = ParsePropTypePointLock(node, parent, reader); if (setProp) { OnHandlePropTypePointLock(node, parent, propertyName, pointLock, reader); } break; } case CCBPropType.Size: { CCSize size = ParsePropTypeSize(node, parent, reader); if (setProp) { OnHandlePropTypeSize(node, parent, propertyName, size, reader); } break; } case CCBPropType.ScaleLock: { float[] scaleLock = ParsePropTypeScaleLock(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeScaleLock(node, parent, propertyName, scaleLock, reader); } break; } case CCBPropType.Float: { float f = ParsePropTypeFloat(node, parent, reader); if (setProp) { OnHandlePropTypeFloat(node, parent, propertyName, f, reader); } break; } case CCBPropType.Degrees: { float degrees = ParsePropTypeDegrees(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeDegrees(node, parent, propertyName, degrees, reader); } break; } case CCBPropType.FloatScale: { float floatScale = ParsePropTypeFloatScale(node, parent, reader); if (setProp) { OnHandlePropTypeFloatScale(node, parent, propertyName, floatScale, reader); } break; } case CCBPropType.Integer: { int integer = ParsePropTypeInteger(node, parent, reader); if (setProp) { OnHandlePropTypeInteger(node, parent, propertyName, integer, reader); } break; } case CCBPropType.IntegerLabeled: { int integerLabeled = ParsePropTypeIntegerLabeled(node, parent, reader); if (setProp) { OnHandlePropTypeIntegerLabeled(node, parent, propertyName, integerLabeled, reader); } break; } case CCBPropType.FloatVar: { float[] floatVar = ParsePropTypeFloatVar(node, parent, reader); if (setProp) { OnHandlePropTypeFloatVar(node, parent, propertyName, floatVar, reader); } break; } case CCBPropType.Check: { bool check = ParsePropTypeCheck(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeCheck(node, parent, propertyName, check, reader); } break; } case CCBPropType.SpriteFrame: { CCSpriteFrame ccSpriteFrame = ParsePropTypeSpriteFrame(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeSpriteFrame(node, parent, propertyName, ccSpriteFrame, reader); } break; } case CCBPropType.Animation: { CCAnimation ccAnimation = ParsePropTypeAnimation(node, parent, reader); if (setProp) { OnHandlePropTypeAnimation(node, parent, propertyName, ccAnimation, reader); } break; } case CCBPropType.Texture: { CCTexture2D ccTexture2D = ParsePropTypeTexture(node, parent, reader); if (setProp) { OnHandlePropTypeTexture(node, parent, propertyName, ccTexture2D, reader); } break; } case CCBPropType.Byte: { byte b = ParsePropTypeByte(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeByte(node, parent, propertyName, b, reader); } break; } case CCBPropType.Color3: { CCColor3B color3B = ParsePropTypeColor3(node, parent, reader, propertyName); if (setProp) { OnHandlePropTypeColor3(node, parent, propertyName, color3B, reader); } break; } case CCBPropType.Color4FVar: { CCColor4F[] color4FVar = ParsePropTypeColor4FVar(node, parent, reader); if (setProp) { OnHandlePropTypeColor4FVar(node, parent, propertyName, color4FVar, reader); } break; } case CCBPropType.Flip: { bool[] flip = ParsePropTypeFlip(node, parent, reader); if (setProp) { OnHandlePropTypeFlip(node, parent, propertyName, flip, reader); } break; } case CCBPropType.Blendmode: { CCBlendFunc blendFunc = ParsePropTypeBlendFunc(node, parent, reader); if (setProp) { OnHandlePropTypeBlendFunc(node, parent, propertyName, blendFunc, reader); } break; } case CCBPropType.FntFile: { string fntFile = ParsePropTypeFntFile(node, parent, reader); if (setProp) { OnHandlePropTypeFntFile(node, parent, propertyName, fntFile, reader); } break; } case CCBPropType.FontTTF: { string fontTTF = ParsePropTypeFontTTF(node, parent, reader); if (setProp) { OnHandlePropTypeFontTTF(node, parent, propertyName, fontTTF, reader); } break; } case CCBPropType.String: { string s = ParsePropTypeString(node, parent, reader); if (setProp) { OnHandlePropTypeString(node, parent, propertyName, s, reader); } break; } case CCBPropType.Text: { string text = ParsePropTypeText(node, parent, reader); if (setProp) { OnHandlePropTypeText(node, parent, propertyName, text, reader); } break; } case CCBPropType.Block: { BlockData blockData = ParsePropTypeBlock(node, parent, reader); if (setProp) { OnHandlePropTypeBlock(node, parent, propertyName, blockData, reader); } break; } case CCBPropType.BlockCCControl: { BlockCCControlData blockCCControlData = ParsePropTypeBlockCcControl(node, parent, reader); if (setProp && blockCCControlData != null) { OnHandlePropTypeBlockCcControl(node, parent, propertyName, blockCCControlData, reader); } break; } case CCBPropType.CCBFile: { CCNode ccbFileNode = ParsePropTypeCcbFile(node, parent, reader); if (setProp) { OnHandlePropTypeCCBFile(node, parent, propertyName, ccbFileNode, reader); } break; } default: //ASSERT_FAIL_UNEXPECTED_PROPERTYTYPE(type); break; } } }
public SpriteOffsetAnchorSkew() { 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++) { tmp = string.Format("grossini_dance_{0:00}.png", j + 1); 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)); AddChild(sprite, 0); } }
private void ParseVersion2(PlistDictionary animations) { CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; foreach (var pElement in animations) { string name = pElement.Key; PlistDictionary animationDict = pElement.Value.AsDictionary; int loops = animationDict["loops"].AsInt; bool restoreOriginalFrame = animationDict["restoreOriginalFrame"].AsBool; PlistArray frameArray = animationDict["frames"].AsArray; if (frameArray == null) { CCLog.Log( "cocos2d: CCAnimationCache: Animation '{0}' found in dictionary without any frames - cannot add to animation cache.", name); continue; } // Array of AnimationFrames var array = new List<CCAnimationFrame>(frameArray.Count); foreach (PlistObjectBase pObj in frameArray) { PlistDictionary entry = pObj.AsDictionary; string spriteFrameName = entry["spriteframe"].AsString; CCSpriteFrame spriteFrame = frameCache.SpriteFrameByName(spriteFrameName); if (spriteFrame == null) { CCLog.Log( "cocos2d: CCAnimationCache: Animation '{0}' refers to frame '{1}' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", name, spriteFrameName); continue; } float delayUnits = entry["delayUnits"].AsFloat; PlistDictionary userInfo = entry["notification"].AsDictionary; var animFrame = new CCAnimationFrame(); animFrame.InitWithSpriteFrame(spriteFrame, delayUnits, userInfo); array.Add(animFrame); } float delayPerUnit = animationDict["delayPerUnit"].AsFloat; var animation = new CCAnimation(array, delayPerUnit, (uint) loops); animation.RestoreOriginalFrame = restoreOriginalFrame; SharedAnimationCache.AddAnimation(animation, name); } }
private void ParseVersion1(PlistDictionary animations) { CCSpriteFrameCache frameCache = CCSpriteFrameCache.SharedSpriteFrameCache; foreach (var pElement in animations) { PlistDictionary animationDict = pElement.Value.AsDictionary; PlistArray frameNames = animationDict["frames"].AsArray; float delay = animationDict["delay"].AsFloat; //CCAnimation* animation = NULL; if (frameNames == null) { CCLog.Log( "cocos2d: CCAnimationCache: Animation '{0}' found in dictionary without any frames - cannot add to animation cache.", pElement.Key); continue; } var frames = new List<CCAnimationFrame>(frameNames.Count); foreach (PlistObjectBase pObj in frameNames) { string frameName = pObj.AsString; CCSpriteFrame spriteFrame = frameCache.SpriteFrameByName(frameName); if (spriteFrame == null) { CCLog.Log( "cocos2d: CCAnimationCache: Animation '{0}' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", pElement.Key, frameName); continue; } var animFrame = new CCAnimationFrame(); animFrame.InitWithSpriteFrame(spriteFrame, 1, null); frames.Add(animFrame); } if (frames.Count == 0) { CCLog.Log( "cocos2d: CCAnimationCache: None of the frames for animation '{0}' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", pElement.Key); continue; } else if (frames.Count != frameNames.Count) { CCLog.Log( "cocos2d: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '{0}' may be missing.", pElement.Key); } CCAnimation animation = new CCAnimation(frames, delay, 1); SharedAnimationCache.AddAnimation(animation, pElement.Key); } }
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 SpriteBatchNodeChildren() { CCSize s = CCDirector.SharedDirector.WinSize; // parents CCSpriteBatchNode batch = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist"); CCSprite sprite1 = new CCSprite("grossini_dance_01.png"); sprite1.Position = (new CCPoint(s.Width / 3, s.Height / 2)); CCSprite sprite2 = new CCSprite("grossini_dance_02.png"); sprite2.Position = (new CCPoint(50, 50)); CCSprite sprite3 = new CCSprite("grossini_dance_03.png"); sprite3.Position = (new CCPoint(-50, -50)); batch.AddChild(sprite1); sprite1.AddChild(sprite2); sprite1.AddChild(sprite3); // BEGIN NEW CODE var animFrames = new List<CCSpriteFrame>(); 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 = new CCAnimation(animFrames, 0.2f); sprite1.RunAction(new CCRepeatForever (new CCAnimate (animation))); // END NEW CODE CCActionInterval action = new CCMoveBy (2, new CCPoint(200, 0)); CCActionInterval action_back = (CCActionInterval)action.Reverse(); CCActionInterval action_rot = new CCRotateBy (2, 360); CCActionInterval action_s = new CCScaleBy(2, 2); CCActionInterval action_s_back = (CCActionInterval)action_s.Reverse(); CCActionInterval seq2 = (CCActionInterval)action_rot.Reverse(); sprite2.RunAction(new CCRepeatForever (seq2)); sprite1.RunAction((CCAction)(new CCRepeatForever (action_rot))); sprite1.RunAction((CCAction)(new CCRepeatForever ((CCActionInterval)(new CCSequence(action, action_back))))); sprite1.RunAction((CCAction)(new CCRepeatForever ((CCActionInterval)(new CCSequence(action_s, action_s_back))))); }
public SpriteOffsetAnchorScale() { 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, 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++) { string temp = ""; if (j + 1 < 10) { temp = "0" + (j + 1); } else { temp = (j + 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)); AddChild(sprite, 0); //animFrames->release(); // win32 : memory leak 2010-0415 } }
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); } }