Пример #1
0
 public CCAction getActionByTag(uint tag, CCObject target)
 {
     if (this.m_pTargets.ContainsKey(target))
     {
         tHashElement element = this.m_pTargets[target];
         if (element.actions != null)
         {
             int count = element.actions.Count;
             for (int i = 0; i < count; i++)
             {
                 CCAction action = element.actions[i];
                 if (action.tag == tag)
                 {
                     return(action);
                 }
             }
         }
         else
         {
             CCLog.Log("cocos2d : getActionByTag: Target not found");
         }
     }
     else
     {
         CCLog.Log("cocos2d : getActionByTag: Target not found");
     }
     return(null);
 }
Пример #2
0
        // actions

        /// <summary>
        /// Adds an action with a target.
        ///  If the target is already present, then the action will be added to the existing target.
        ///  If the target is not present, a new instance of this target will be created either paused or not, and the action will be added to the newly created target.
        ///  When the target is paused, the queued actions won't be 'ticked'.
        /// </summary>
        public void addAction(CCAction action, Node target, bool paused)
        {
            Debug.Assert(action != null);
            Debug.Assert(target != null);

            tHashElement element = null;

            if (!m_pTargets.ContainsKey(target))
            {
                element        = new tHashElement();
                element.paused = paused;
                element.target = target;
                m_pTargets.Add(target, element);
            }
            else
            {
                element = m_pTargets[target];
            }

            actionAllocWithHashElement(element);

            Debug.Assert(!element.actions.Contains(action));
            element.actions.Add(action);

            action.StartWithTarget(target);
        }
Пример #3
0
        /// <summary>
        /// Gets an action given its tag an a target
        /// </summary>
        /// <returns>
        /// @return the Action the with the given tag
        /// </returns>
        public CCAction getActionByTag(uint tag, CCObject target)
        {
            Debug.Assert((int)tag != CCAction.INVALID_ACTION_TAGB);

            if (m_pTargets.ContainsKey(target))
            {
                tHashElement element = m_pTargets[target];

                if (element.actions != null)
                {
                    int limit = element.actions.Count;
                    for (int i = 0; i < limit; i++)
                    {
                        CCAction action = element.actions[i];

                        if (action.Tag == (int)tag)
                        {
                            return(action);
                        }
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("cocos2d : getActionByTag: Target not found");
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("cocos2d : getActionByTag: Target not found");
            }

            return(null);
        }
Пример #4
0
 protected void actionAllocWithHashElement(tHashElement element)
 {
     if (element.actions == null)
     {
         element.actions = new List <CCAction>();
     }
 }
Пример #5
0
        /// <summary>
        /// Removes all actions from a certain target.
        /// All the actions that belongs to the target will be removed.
        /// </summary>
        public void removeAllActionsFromTarget(CCObject target)
        {
            if (target == null)
            {
                return;
            }

            if (m_pTargets.ContainsKey(target))
            {
                tHashElement element = m_pTargets[target];

                if (element.actions.Contains(element.currentAction) && (!element.currentActionSalvaged))
                {
                    element.currentActionSalvaged = true;
                }

                element.actions.Clear();
                if (m_pCurrentTarget == element)
                {
                    m_bCurrentTargetSalvaged = true;
                }
                else
                {
                    deleteHashElement(element);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("cocos2d: removeAllActionsFromTarget: Target not found");
            }
        }
Пример #6
0
        protected void removeActionAtIndex(int index, tHashElement element)
        {
            CCAction action = element.actions[index];

            if (action == element.currentAction && (!element.currentActionSalvaged))
            {
                element.currentActionSalvaged = true;
            }

            element.actions.RemoveAt(index);

            // update actionIndex in case we are in tick. looping over the actions
            if (element.actionIndex >= index)
            {
                element.actionIndex--;
            }

            if (element.actions.Count == 0)
            {
                if (m_pCurrentTarget == element)
                {
                    m_bCurrentTargetSalvaged = true;
                }
                else
                {
                    deleteHashElement(element);
                }
            }
        }
Пример #7
0
 public void removeAllActionsFromTarget(CCObject target)
 {
     if (target != null)
     {
         if (this.m_pTargets.ContainsKey(target))
         {
             tHashElement element = this.m_pTargets[target];
             if (element.actions.Contains(element.currentAction) && !element.currentActionSalvaged)
             {
                 element.currentActionSalvaged = true;
             }
             element.actions.Clear();
             if (this.m_pCurrentTarget == element)
             {
                 this.m_bCurrentTargetSalvaged = true;
             }
             else
             {
                 this.deleteHashElement(element);
             }
         }
         else
         {
             CCLog.Log("cocos2d: removeAllActionsFromTarget: Target not found");
         }
     }
 }
Пример #8
0
        protected void removeActionAtIndex(int index, tHashElement element)
        {
            CCAction action = element.actions[index];

            if ((action == element.currentAction) && !element.currentActionSalvaged)
            {
                element.currentActionSalvaged = true;
            }
            element.actions.RemoveAt(index);
            if (element.actionIndex >= index)
            {
                element.actionIndex--;
            }
            if (element.actions.Count == 0)
            {
                if (this.m_pCurrentTarget == element)
                {
                    this.m_bCurrentTargetSalvaged = true;
                }
                else
                {
                    this.deleteHashElement(element);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Gets an action given its tag an a target
        /// </summary>
        /// <returns>
        /// @return the Action the with the given tag
        /// </returns>
        public CCAction getActionByTag(uint tag, CCObject target)
        {
            Debug.Assert((int)tag != (int)ActionTag.kCCActionTagInvalid);

            if (m_pTargets.ContainsKey(target))
            {
                tHashElement element = m_pTargets[target];

                if (element.actions != null)
                {
                    int limit = element.actions.Count;
                    for (int i = 0; i < limit; i++)
                    {
                        CCAction action = element.actions[i];

                        if (action.tag == (int)tag)
                        {
                            return(action);
                        }
                    }
                }
                else
                {
                    CCLog.Log("cocos2d : getActionByTag: Target not found");
                }
            }
            else
            {
                CCLog.Log("cocos2d : getActionByTag: Target not found");
            }

            return(null);
        }
Пример #10
0
        // actions

        /// <summary>
        /// Adds an action with a target. 
        ///  If the target is already present, then the action will be added to the existing target.
        ///  If the target is not present, a new instance of this target will be created either paused or not, and the action will be added to the newly created target.
        ///  When the target is paused, the queued actions won't be 'ticked'.
        /// </summary>
        public void addAction(CCAction action, CCNode target, bool paused)
        {
            Debug.Assert(action != null);
            Debug.Assert(target != null);

            tHashElement element = null;
            if (!m_pTargets.ContainsKey(target))
            {
                element = new tHashElement();
                element.paused = paused;
                element.target = target;
                m_pTargets.Add(target, element);
            }
            else
            {
                element = m_pTargets[target];
            }

            actionAllocWithHashElement(element);

            Debug.Assert(!element.actions.Contains(action));
            element.actions.Add(action);

            action.startWithTarget(target);
        }
Пример #11
0
        /// <summary>
        /// Returns the numbers of actions that are running in a certain target.
        /// Composable actions are counted as 1 action. Example:
        /// - If you are running 1 Sequence of 7 actions, it will return 1.
        /// - If you are running 7 Sequences of 2 actions, it will return 7.
        /// </summary>
        public uint numberOfRunningActionsInTarget(CCObject target)
        {
            if (m_pTargets.ContainsKey(target))
            {
                tHashElement element = m_pTargets[target];
                return((element.actions != null) ? (uint)element.actions.Count : 0);
            }

            return(0);
        }
Пример #12
0
        public void update(float dt)
        {
            CCObject[] keys = new CCObject[m_pTargets.Keys.Count];
            m_pTargets.Keys.CopyTo(keys, 0);

            for (int i = 0; i < keys.Length; i++)
            {
                if (!m_pTargets.ContainsKey(keys[i]))
                {
                    // http://www.cocos2d-x.org/boards/17/topics/11072
                    continue;
                }
                tHashElement elt = m_pTargets[keys[i]];
                m_pCurrentTarget         = elt;
                m_bCurrentTargetSalvaged = false;

                if (!m_pCurrentTarget.paused)
                {
                    // The 'actions' may change while inside this loop.
                    for (m_pCurrentTarget.actionIndex = 0; m_pCurrentTarget.actionIndex < m_pCurrentTarget.actions.Count;
                         m_pCurrentTarget.actionIndex++)
                    {
                        m_pCurrentTarget.currentAction = m_pCurrentTarget.actions[m_pCurrentTarget.actionIndex];
                        if (m_pCurrentTarget.currentAction == null)
                        {
                            continue;
                        }

                        m_pCurrentTarget.currentActionSalvaged = false;

                        m_pCurrentTarget.currentAction.Step(dt);

                        if (m_pCurrentTarget.currentAction.IsDone())
                        {
                            m_pCurrentTarget.currentAction.Stop();

                            CCAction action = m_pCurrentTarget.currentAction;
                            // Make currentAction nil to prevent removeAction from salvaging it.
                            m_pCurrentTarget.currentAction = null;
                            removeAction(action);
                        }

                        m_pCurrentTarget.currentAction = null;
                    }
                }

                // only delete currentTarget if no actions were scheduled during the cycle (issue #481)
                if (m_bCurrentTargetSalvaged && m_pCurrentTarget.actions.Count == 0)
                {
                    deleteHashElement(m_pCurrentTarget);
                }
            }

            m_pCurrentTarget = null;
        }
Пример #13
0
        public uint numberOfRunningActionsInTarget(CCObject target)
        {
            if (!this.m_pTargets.ContainsKey(target))
            {
                return(0);
            }
            tHashElement element = this.m_pTargets[target];

            if (element.actions == null)
            {
                return(0);
            }
            return((uint)element.actions.Count);
        }
Пример #14
0
 public void removeActionByTag(int tag, CCObject target)
 {
     if (this.m_pTargets.ContainsKey(target))
     {
         tHashElement element = this.m_pTargets[target];
         int          count   = element.actions.Count;
         for (int i = 0; i < count; i++)
         {
             CCAction action = element.actions[i];
             if ((action.tag == tag) && (action.originalTarget == target))
             {
                 this.removeActionAtIndex(i, element);
                 return;
             }
         }
     }
 }
Пример #15
0
        protected void deleteHashElement(tHashElement element)
        {
            element.actions.Clear();
            element.target = null;
            CCObject key = null;

            foreach (KeyValuePair <CCObject, tHashElement> pair in this.m_pTargets)
            {
                if (element == pair.Value)
                {
                    key = pair.Key;
                    break;
                }
            }
            if (key != null)
            {
                this.m_pTargets.Remove(key);
            }
        }
Пример #16
0
        protected void deleteHashElement(tHashElement element)
        {
            element.actions.Clear();
            element.target = null;
            CCObject keyToDelete = null;

            foreach (KeyValuePair <CCObject, tHashElement> kvp in m_pTargets)
            {
                if (element == kvp.Value)
                {
                    keyToDelete = kvp.Key;
                    break;
                }
            }

            if (keyToDelete != null)
            {
                m_pTargets.Remove(keyToDelete);
            }
        }
Пример #17
0
 public void removeAction(CCAction action)
 {
     if (action != null)
     {
         CCObject originalTarget = action.originalTarget;
         if (this.m_pTargets.ContainsKey(originalTarget))
         {
             tHashElement element = this.m_pTargets[originalTarget];
             int          index   = element.actions.IndexOf(action);
             if (index != -1)
             {
                 this.removeActionAtIndex(index, element);
             }
         }
         else
         {
             CCLog.Log("cocos2d: removeAction: Target not found");
         }
     }
 }
Пример #18
0
 public void update(float dt)
 {
     CCObject[] array = new CCObject[this.m_pTargets.Keys.Count];
     this.m_pTargets.Keys.CopyTo(array, 0);
     for (int i = 0; i < array.Length; i++)
     {
         if (this.m_pTargets.ContainsKey(array[i]))
         {
             tHashElement element = this.m_pTargets[array[i]];
             this.m_pCurrentTarget         = element;
             this.m_bCurrentTargetSalvaged = false;
             if (!this.m_pCurrentTarget.paused)
             {
                 this.m_pCurrentTarget.actionIndex = 0;
                 while (this.m_pCurrentTarget.actionIndex < this.m_pCurrentTarget.actions.Count)
                 {
                     this.m_pCurrentTarget.currentAction = this.m_pCurrentTarget.actions[this.m_pCurrentTarget.actionIndex];
                     if (this.m_pCurrentTarget.currentAction != null)
                     {
                         this.m_pCurrentTarget.currentActionSalvaged = false;
                         this.m_pCurrentTarget.currentAction.step(dt);
                         if (this.m_pCurrentTarget.currentAction.isDone())
                         {
                             this.m_pCurrentTarget.currentAction.stop();
                             CCAction currentAction = this.m_pCurrentTarget.currentAction;
                             this.m_pCurrentTarget.currentAction = null;
                             this.removeAction(currentAction);
                         }
                         this.m_pCurrentTarget.currentAction = null;
                     }
                     this.m_pCurrentTarget.actionIndex++;
                 }
             }
             if (this.m_bCurrentTargetSalvaged && (this.m_pCurrentTarget.actions.Count == 0))
             {
                 this.deleteHashElement(this.m_pCurrentTarget);
             }
         }
     }
     this.m_pCurrentTarget = null;
 }
Пример #19
0
        public void addAction(CCAction action, CCNode target, bool paused)
        {
            tHashElement element = null;

            if (!this.m_pTargets.ContainsKey(target))
            {
                element = new tHashElement
                {
                    paused = paused,
                    target = target
                };
                this.m_pTargets.Add(target, element);
            }
            else
            {
                element = this.m_pTargets[target];
            }
            this.actionAllocWithHashElement(element);
            element.actions.Add(action);
            action.startWithTarget(target);
        }
Пример #20
0
        /// <summary>
        /// Removes an action given its tag and the target
        /// </summary>
        public void removeActionByTag(int tag, CCObject target)
        {
            Debug.Assert((tag != CCAction.INVALID_ACTION_TAGB));
            Debug.Assert(target != null);

            if (m_pTargets.ContainsKey(target))
            {
                tHashElement element = m_pTargets[target];

                int limit = element.actions.Count;
                for (int i = 0; i < limit; i++)
                {
                    CCAction action = element.actions[i];

                    if (action.Tag == (int)tag && action.OriginalTarget == target)
                    {
                        removeActionAtIndex(i, element);
                        break;
                    }
                }
            }
        }
Пример #21
0
        /// <summary>
        /// Removes an action given an action reference.
        /// </summary>
        public void removeAction(CCAction action)
        {
            if (action == null)
            {
                return;
            }

            CCObject target = action.OriginalTarget;

            if (m_pTargets.ContainsKey(target))
            {
                tHashElement element = m_pTargets[target];
                int          i       = element.actions.IndexOf(action);

                if (i != -1)
                {
                    removeActionAtIndex(i, element);
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("cocos2d: removeAction: Target not found");
            }
        }
Пример #22
0
        /// <summary>
        /// Removes an action given an action reference.
        /// </summary>
        public void removeAction(CCAction action)
        {
            if (action == null)
            {
                return;
            }

            CCObject target = action.originalTarget;

            if (m_pTargets.ContainsKey(target))
            {
                tHashElement element = m_pTargets[target];
                int          i       = element.actions.IndexOf(action);

                if (i != -1)
                {
                    removeActionAtIndex(i, element);
                }
            }
            else
            {
                CCLog.Log("cocos2d: removeAction: Target not found");
            }
        }
Пример #23
0
        protected void removeActionAtIndex(int index, tHashElement element)
        {
            CCAction action = element.actions[index];

            if (action == element.currentAction && (!element.currentActionSalvaged))
            {
                element.currentActionSalvaged = true;
            }

            element.actions.RemoveAt(index);

            // update actionIndex in case we are in tick. looping over the actions
            if (element.actionIndex >= index)
            {
                element.actionIndex--;
            }

            if (element.actions.Count == 0)
            {
                if (m_pCurrentTarget == element)
                {
                    m_bCurrentTargetSalvaged = true;
                }
                else
                {
                    deleteHashElement(element);
                }
            }
        }
Пример #24
0
 protected void actionAllocWithHashElement(tHashElement element)
 {
     if (element.actions == null)
     {
         element.actions = new List<CCAction>();
     }
 }
Пример #25
0
        protected void deleteHashElement(tHashElement element)
        {
            element.actions.Clear();
            element.target = null;
            CCObject keyToDelete = null;
            foreach (KeyValuePair<CCObject, tHashElement> kvp in m_pTargets)
            {
                if (element == kvp.Value)
                {
                    keyToDelete = kvp.Key;
                    break;
                }
            }

            if (keyToDelete != null)
            {
                m_pTargets.Remove(keyToDelete);
            }
        }
Пример #26
0
        public void update(float dt)
        {
            CCObject[] keys = new CCObject[m_pTargets.Keys.Count];
            m_pTargets.Keys.CopyTo(keys, 0);

            for (int i = 0; i < keys.Length; i++)
            {
                tHashElement elt = m_pTargets[keys[i]];
                m_pCurrentTarget = elt;
                m_bCurrentTargetSalvaged = false;

                if (!m_pCurrentTarget.paused)
                {
                    // The 'actions' may change while inside this loop.
                    for (m_pCurrentTarget.actionIndex = 0; m_pCurrentTarget.actionIndex < m_pCurrentTarget.actions.Count;
                        m_pCurrentTarget.actionIndex++)
                    {
                        m_pCurrentTarget.currentAction = m_pCurrentTarget.actions[m_pCurrentTarget.actionIndex];
                        if (m_pCurrentTarget.currentAction == null)
                        {
                            continue;
                        }

                        m_pCurrentTarget.currentActionSalvaged = false;

                        m_pCurrentTarget.currentAction.step(dt);

                        if (m_pCurrentTarget.currentAction.isDone())
                        {
                            m_pCurrentTarget.currentAction.stop();

                            CCAction action = m_pCurrentTarget.currentAction;
                            // Make currentAction nil to prevent removeAction from salvaging it.
                            m_pCurrentTarget.currentAction = null;
                            removeAction(action);
                        }

                        m_pCurrentTarget.currentAction = null;
                    }
                }

                // only delete currentTarget if no actions were scheduled during the cycle (issue #481)
                if (m_bCurrentTargetSalvaged && m_pCurrentTarget.actions.Count == 0)
                {
                    deleteHashElement(m_pCurrentTarget);
                }
            }

            m_pCurrentTarget = null;
        }