コード例 #1
0
        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);
            }
        }
コード例 #2
0
        void stopAnimation()
        {
            if (!_isAnimating)
            {
                return;
            }

            CCDebug.Log("cocos2d: animation stopped");

            _displayLink.invalidate(this);
            _isAnimating = false;
        }
コード例 #3
0
 public static void WriteToFile(string path, string text, ZipDelegate zip = null)
 {
     CCDebug.Log("FileUtils:writeToFile {0}", path);
     if (zip != null)
     {
         text = zip.zip(text);
     }
     if (File.Exists(path))
     {
         File.Delete(path);
     }
     File.WriteAllText(path, text);
 }
コード例 #4
0
        public void removeChildByTag(string tag, bool cleanup = true)
        {
            NSUtils.Assert(tag != null, "Invalid tag");

            CCNode child = getChildByTag(tag);

            if (child == null)
            {
                CCDebug.Log("cocos2d: removeChildByTag: child not found!");
            }
            else
            {
                removeChildAndCleanup(child, cleanup);
            }
        }
コード例 #5
0
        protected CCDirector()
        {
            CCDebug.Log("cocos2d: cocos2d-iphone v2.1");
            // scenes
            _runningScene = null;
            _nextScene    = null;

//			_notificationNode = nil;

            _oldAnimationInterval = _animationInterval = 1.0f / kDefaultFPS;
            _scenesStack          = new Stack <CCScene> (10);

            // Set default projection (3D)
//			_projection = kCCDirectorProjectionDefault;

            // projection delegate if "Custom" projection is used
//			_delegate = nil;

            // FPS
            _displayStats = false;

            _displayError = false;

//			_totalFrames = _frames = 0;

            // paused ?
            _isPaused = false;

            // running thread
//			_runningThread = null;

            // scheduler
            _scheduler = new CCScheduler();

            // action manager
            _actionManager = new CCActionManager();
            _scheduler.scheduleUpdate(_actionManager, CCScheduler.kCCPrioritySystem, false);

            _winSizeInPixels = Vector2.zero;


            //CCDirectorIOS
//			_ccContentScaleFactor = 1;
//			_isContentScaleSupported = false;
            _touchDispatcher = new CCTouchDispatcher();
        }
コード例 #6
0
        public void scheduleBlockForKey(string key, System.Object owner, float interval, uint repeat, float delay, bool paused, TICK_IMP block)
        {
            NSUtils.Assert(block != null, "Argument block must be non-nil");
            NSUtils.Assert(owner != null, "Argument owner must be non-nil");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(owner.GetHashCode());

            if (element == null)
            {
                element        = new tHashTimerEntry();
                element.target = owner;
                hashForTimers.HASH_ADD_INT(owner.GetHashCode(), element);

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = paused;
            }
            else
            {
                NSUtils.Assert(element.paused == paused, "CCScheduler. Trying to schedule a block with a pause value different than the target");
            }


            if (element.timers == null)
            {
                element.timers = new List <CCTimer> (10);
            }
            else
            {
                var enumerator = element.timers.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    CCTimer timer = enumerator.Current;
                    if (timer is CCTimerBlock && key == ((CCTimerBlock)timer).key)
                    {
                        CCDebug.Log("CCScheduler#scheduleBlock. Block already scheduled. Updating interval from: {0:0.0000} to {1:0.0000}", timer.interval, interval);
                        timer.interval = interval;
                        return;
                    }
                }
            }

            CCTimerBlock timerBlock = new CCTimerBlock(owner, interval, key, block, repeat, delay);

            element.timers.Add(timerBlock);
        }
コード例 #7
0
        /** The scheduled method will be called every 'interval' seconds.
         * If paused is YES, then it won't be called until it is resumed.
         * If 'interval' is 0, it will be called every frame, but if so, it recommended to use 'scheduleUpdateForTarget:' instead.
         * If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
         * repeat lets the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously
         * delay is the amount of time the action will wait before it'll start
         *
         * @since v0.99.3, repeat and delay added in v1.1
         */
        public void schedule(TICK_IMP selector, System.Object target, float interval, uint repeat, bool paused, float delay = 0)
        {
            NSUtils.Assert(selector != null, "Argument selector must be non-nil");
            NSUtils.Assert(target != null, "Argument target must be non-nil");

            tHashTimerEntry element = hashForTimers.HASH_FIND_INT(target.GetHashCode());

            if (element == null)
            {
                element        = new tHashTimerEntry();
                element.target = target;
                hashForTimers.HASH_ADD_INT(target.GetHashCode(), element);

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = paused;
            }
            else
            {
                NSUtils.Assert(element.paused == paused, "CCScheduler. Trying to schedule a selector with a pause value different than the target");
            }


            if (element.timers == null)
            {
                element.timers = new List <CCTimer> (10);
            }
            else
            {
                var enumerator = element.timers.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    CCTimer timer = enumerator.Current;
                    if (timer is CCTimerTargetSelector && selector == ((CCTimerTargetSelector)timer).selector)
                    {
                        CCDebug.Log("CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: {0:0.0000} to {1:0.0000}", timer.interval, interval);
                        timer.interval = interval;
                        return;
                    }
                }
            }
            CCTimerTargetSelector timerSelector = new CCTimerTargetSelector(target, selector, interval, repeat, delay);

            element.timers.Add(timerSelector);
        }
コード例 #8
0
        /** Adds an animation from an NSDictionary
         * Make sure that the frames were previously loaded in the CCSpriteFrameCache.
         * @since v1.1
         */
        public void addAnimationsWithDictionary(NSDictionary dictionary)
        {
            NSDictionary animations = dictionary.objectForKey <NSDictionary>("animations");

            if (animations == null)
            {
                CCDebug.Log("cocos2d: CCAnimationCache: No animations were found in provided dictionary.");
                return;
            }

            int          version    = 1;
            NSDictionary properties = dictionary.objectForKey <NSDictionary>("properties");

            if (properties != null)
            {
                version = properties.objectForKey <int>("format");
            }

            NSArray spritesheets = properties.objectForKey <NSArray>("spritesheets");

            var enumerator = spritesheets.GetEnumerator();

            while (enumerator.MoveNext())
            {
                string name = (string)enumerator.Current;
                CCSpriteFrameCache.sharedSpriteFrameCache.addSpriteFramesWithFile(name);
            }
            switch (version)
            {
            case 1:
                parseVersion1(animations);
                break;

            case 2:
                parseVersion2(animations);
                break;

            default:
                NSUtils.Assert(false, "Invalid animation format");
                break;
            }
        }
コード例 #9
0
        void startAnimation()
        {
            _nextDeltaTimeZero = true;

            if (_isAnimating)
            {
                return;
            }


            // approximate frame rate
            // assumes device refreshes at 60 fps
            int frameInterval = Mathf.FloorToInt(_animationInterval * 60.0f);


            CCDebug.Log("cocos2d: animation started with frame interval: {0:0.00}", 60.0f / frameInterval);

            _displayLink.registWithTarget(this, mainLoop, OnGUI);

            _isAnimating = true;
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        public void Debug()
        {
            string s = flash.trace();

            CCDebug.Log(s);
        }
コード例 #12
0
 public virtual void update(float dt)
 {
     CCDebug.Log("[Action update]. override me");
 }
コード例 #13
0
 public virtual void step(float dt)
 {
     CCDebug.Log("[Action step]. override me");
 }