/** Adds a CCSpriteFrame to a CCAnimation. * The frame will be added with one "delay unit". */ public void addSpriteFrame(CCSpriteFrame frame) { CCAnimationFrame animFrame = new CCAnimationFrame(frame, 1, null); _frames.Add(animFrame); _totalDelayUnits++; }
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); } }
public override void update(float t) { // if t==1, ignore. Animation should finish with t==1 if (FloatUtils.Small(t, 1.0f)) { t *= _animation.loops; // new loop? If so, reset frame counter uint loopNumber = (uint)t; if (loopNumber > _executedLoops) { _nextFrame = 0; _executedLoops++; } // new t for animations t = (t % 1.0f); } List <CCAnimationFrame> frames = _animation.frames; uint numberOfFrames = (uint)frames.Count; CCSpriteFrame frameToDisplay = null; for (int i = _nextFrame; i < numberOfFrames; i++) { float splitTime = _splitTimes[i]; if (FloatUtils.ES(splitTime, t)) { CCAnimationFrame frame = frames[i]; frameToDisplay = frame.spriteFrame; ((CCSprite)_target).displayedFrame = frameToDisplay; NSDictionary dict = frame.userInfo; if (dict != null) { // NSNotificationCenter.defaultCenter.postNotification(CCAnimationFrameDisplayedNotification, _target, dict); _nextFrame = i + 1; } } // Issue 1438. Could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS else { break; } } }
/** Initializes a CCAnimation with an array of CCSpriteFrames and a delay between frames in seconds. * The frames will be added with one "delay unit". * @since v0.99.5 */ public void initWithSpriteFrames(List <CCSpriteFrame> array, float delay) { _loops = 1; _delayPerUnit = delay; this.frames = new List <CCAnimationFrame> (array == null?0:array.Count); if (array != null) { var enumerator = array.GetEnumerator(); while (enumerator.MoveNext()) { var frame = enumerator.Current; CCAnimationFrame animFrame = new CCAnimationFrame(frame, 1, null); this.frames.Add(animFrame); _totalDelayUnits++; } } }
public CCAnimationFrame copy() { CCAnimationFrame action = new CCAnimationFrame(_spriteFrame, _delayUnits, _userinfo == null?null:_userinfo.Clone() as NSDictionary); return(action); }
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); } }