public object Copy(ICopyable pZone) { CCAnimationFrame pCopy; if (pZone != null) { //in case of being called at sub class pCopy = (CCAnimationFrame) (pZone); } else { pCopy = new CCAnimationFrame(); } pCopy.InitWithSpriteFrame((CCSpriteFrame) m_pSpriteFrame.Copy(), m_fDelayUnits, m_pUserInfo); return pCopy; }
public object Copy(ICopyable pZone) { CCAnimationFrame pCopy; if (pZone != null) { //in case of being called at sub class pCopy = (CCAnimationFrame)(pZone); } else { pCopy = new CCAnimationFrame(); } pCopy.InitWithSpriteFrame((CCSpriteFrame)m_pSpriteFrame.Copy(), m_fDelayUnits, m_pUserInfo); return(pCopy); }
protected CCAnimationFrame(CCAnimationFrame animFrame) { SpriteFrame = animFrame.SpriteFrame; DelayUnits = animFrame.DelayUnits; UserInfo = animFrame.UserInfo; }
void parseVersion1(NSDictionary animations) { CCSpriteFrameCache frameCache = CCSpriteFrameCache.sharedSpriteFrameCache; var enumerator = animations.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<object, object> kv = enumerator.Current; string name = (string)kv.Key; NSDictionary animationDict = (NSDictionary)kv.Value; ArrayList frameNames = (ArrayList)animationDict["frames"]; float delay = (float)animationDict["delay"]; CCAnimation animation = null; if ( frameNames == null ) { CCDebug.Log("cocos2d: CCAnimationCache: Animation '{0}' found in dictionary without any frames - cannot add to animation cache.", name); continue; } List<CCAnimationFrame> frames = new List<CCAnimationFrame>(frameNames.Count); var framesEnumerator = frameNames.GetEnumerator(); while (framesEnumerator.MoveNext()) { string frameName = (string)framesEnumerator.Current; CCSpriteFrame spriteFrame = frameCache.spriteFrameByName(frameName); if ( spriteFrame == null ) { CCDebug.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, frameName); continue; } CCAnimationFrame animFrame = new CCAnimationFrame(spriteFrame, 1, null); frames.Add(animFrame); } if ( frames.Count == 0 ) { CCDebug.Log("cocos2d: CCAnimationCache: None of the frames for animation '{0}' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", name); continue; } else if ( frames.Count != frameNames.Count ) { CCDebug.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.", name); } animation = new CCAnimation(frames, delay, 1); CCAnimationCache.sharedAnimationCache.addAnimation(animation, name); } }
void parseVersion2(NSDictionary animations) { CCSpriteFrameCache frameCache = CCSpriteFrameCache.sharedSpriteFrameCache; var enumerator = animations.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<object, object> kv = enumerator.Current; string name = (string)kv.Key; NSDictionary animationDict = (NSDictionary)kv.Value; int loops = 0; object loopsObj = loops; if(!animationDict.TryGetValue("loops", out loopsObj)){ loops = 1; }else{ loops = (int)loopsObj; } bool restoreOriginalFrame = (bool)animationDict["restoreOriginalFrame"]; NSArray frameArray = (NSArray)animationDict["frames"]; if ( frameArray == null ) { CCDebug.Log(@"cocos2d: CCAnimationCache: Animation '%@' found in dictionary without any frames - cannot add to animation cache.", name); continue; } // Array of AnimationFrames List<CCAnimationFrame> array = new List<CCAnimationFrame>(frameArray.Count); var frameArrayEnumerator = frameArray.GetEnumerator(); while (frameArrayEnumerator.MoveNext()) { NSDictionary entry = (NSDictionary)frameArrayEnumerator.Current; string spriteFrameName = (string)entry["spriteframe"]; CCSpriteFrame spriteFrame = frameCache.spriteFrameByName(spriteFrameName); if( spriteFrame==null ) { CCDebug.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 = float.Parse(entry["delayUnits"].ToString()); NSDictionary userInfo = entry.objectForKey<NSDictionary>("notification"); CCAnimationFrame animFrame = new CCAnimationFrame(spriteFrame, delayUnits, userInfo); array.Add(animFrame); } float delayPerUnit = (float)animationDict["delayPerUnit"]; CCAnimation animation = new CCAnimation (array, delayPerUnit, (uint)loops); animation.restoreOriginalFrame=restoreOriginalFrame; CCAnimationCache.sharedAnimationCache.addAnimation(animation, name); } }
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 '%s' 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 '%s' refers to frame '%s' 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 '%s' 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 '%s' 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 '%s' 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 '%s' may be missing.", pElement.Key); } CCAnimation animation = new CCAnimation(frames, delay, 1); SharedAnimationCache.AddAnimation(animation, pElement.Key); } }