Ejemplo n.º 1
0
        /**
         * @language zh_CN
         * 更新骨架和动画。
         * @param passedTime 两帧之间的时间间隔。 (以秒为单位)
         * @see DragonBones.IAnimateble
         * @see DragonBones.WorldClock
         * @version DragonBones 3.0
         */
        public void AdvanceTime(float passedTime)
        {
            if (_armatureData == null)
            {
                DragonBones.Assert(false, "The armature has been disposed.");
                return;
            }
            else if (_armatureData.parent == null)
            {
                DragonBones.Assert(false, "The armature data has been disposed.");
                return;
            }

            // Bones and slots.
            if (_bonesDirty)
            {
                _bonesDirty = false;
                _sortBones();
            }

            if (_slotsDirty)
            {
                _slotsDirty = false;
                _sortSlots();
            }

            var prevCacheFrameIndex = _animation._cacheFrameIndex;

            // Update animations.
            _animation._advanceTime(passedTime);

            var currentCacheFrameIndex = _animation._cacheFrameIndex;

            int i = 0, l = 0;

            if (currentCacheFrameIndex < 0 || currentCacheFrameIndex != prevCacheFrameIndex)
            {
                // Update bones.
                for (i = 0, l = _bones.Count; i < l; ++i)
                {
                    var bone = _bones[i];
                    bone._update(currentCacheFrameIndex);
                }

                // Update slots.
                for (i = 0, l = _slots.Count; i < l; ++i)
                {
                    _slots[i]._update(currentCacheFrameIndex);
                }
            }

            //
            if (!_lockDispose)
            {
                _lockDispose = true;

                // Events. (Dispatch event before action.)
                l = _events.Count;
                if (l > 0)
                {
                    for (i = 0; i < l; ++i)
                    {
                        var eventObject = _events[i];
                        _proxy.DispatchEvent(eventObject.type, eventObject);

                        if (eventObject.type == EventObject.SOUND_EVENT)
                        {
                            _eventManager.DispatchEvent(eventObject.type, eventObject);
                        }

                        eventObject.ReturnToPool();
                    }

                    _events.Clear();
                }

                // Actions.
                l = _actions.Count;
                if (l > 0)
                {
                    for (i = 0; i < l; ++i)
                    {
                        var action = _actions[i];
                        if (action.slot != null)
                        {
                            var slot = GetSlot(action.slot.name);
                            if (slot != null)
                            {
                                var childArmature = slot.childArmature;
                                if (childArmature != null)
                                {
                                    childArmature._doAction(action);
                                }
                            }
                        }
                        else if (action.bone != null)
                        {
                            for (int iA = 0, lA = _slots.Count; iA < lA; ++iA)
                            {
                                var childArmature = _slots[iA].childArmature;
                                if (childArmature != null)
                                {
                                    childArmature._doAction(action);
                                }
                            }
                        }
                        else
                        {
                            _doAction(action);
                        }
                    }

                    _actions.Clear();
                }

                _lockDispose = false;
            }

            if (_delayDispose)
            {
                ReturnToPool();
            }
        }
        /**
         * @language zh_CN
         * 更新骨架和动画。 (可以使用时钟实例或显示容器来更新)
         * @param passedTime 两帧之前的时间间隔。 (以秒为单位)
         * @see dragonBones.IAnimateble
         * @see dragonBones.WorldClock
         * @see dragonBones.IArmatureDisplay
         * @version DragonBones 3.0
         */
        public void AdvanceTime(float passedTime)
        {
            if (_animation == null)
            {
                DragonBones.Warn("The armature has been disposed.");
            }

            var scaledPassedTime = passedTime * _animation.timeScale;

            // Animations.
            _animation._advanceTime(scaledPassedTime);

            // Bones and slots.
            if (_bonesDirty)
            {
                _bonesDirty = false;
                _sortBones();
            }

            if (_slotsDirty)
            {
                _slotsDirty = false;
                _sortSlots();
            }

            for (int i = 0, l = _bones.Count; i < l; ++i)
            {
                var bone = _bones [i];
                bone._update(_cacheFrameIndex);
            }

            for (int i = 0, l = _slots.Count; i < l; ++i)
            {
                var slot = _slots [i];
                slot._update(_cacheFrameIndex);

                var childArmature = slot._childArmature;
                if (childArmature != null)
                {
                    if (slot.inheritAnimation) // Animation's time scale will impact to childArmature.
                    {
                        childArmature.AdvanceTime(scaledPassedTime);
                    }
                    else
                    {
                        childArmature.AdvanceTime(passedTime);
                    }
                }
            }

            if (!_lockDispose)
            {
                _lockDispose = true;

                // Actions and events.
                if (_events.Count > 0) // Dispatch event before action.
                {
                    foreach (var evt in _events)
                    {
                        _eventDispatcher.DispatchEvent(evt.type, evt);

                        if (evt.type == EventObject.SOUND_EVENT)
                        {
                            _eventManager.DispatchEvent(evt.type, evt);
                        }

                        evt.ReturnToPool();
                    }

                    _events.Clear();
                }

                if (_actions.Count > 0)
                {
                    foreach (var action in _actions)
                    {
                        if (action.slot != null)
                        {
                            var slot = GetSlot(action.slot.name);
                            if (slot != null)
                            {
                                var childArmature = slot._childArmature;
                                if (childArmature != null)
                                {
                                    childArmature._doAction(action);
                                }
                            }
                        }
                        else if (action.bone != null)
                        {
                            foreach (var slot in _slots)
                            {
                                var childArmature = slot._childArmature;
                                if (childArmature != null)
                                {
                                    childArmature._doAction(action);
                                }
                            }
                        }
                        else
                        {
                            _doAction(action);
                        }
                    }

                    _actions.Clear();
                }

                _lockDispose = false;
            }

            if (_delayDispose)
            {
                ReturnToPool();
            }
        }