Пример #1
0
        public Scene(CocosNode singleChild)
            : this()
        {
            if (singleChild == null) {
                throw new ArgumentNullException("singleChild");
            }

            AddChild(singleChild);
        }
Пример #2
0
        public CocosNode AddChild(CocosNode child, int z, PointF parallaxRatio, PointF positionOffset)
        {
            if (child == null) {
                throw new ArgumentNullException("child");
            }

            NodeBox box = new NodeBox(parallaxRatio, positionOffset, child);
            _parallaxNodes.Add(box);

            float x = Position.X * parallaxRatio.X + positionOffset.X;
            float y = Position.Y * parallaxRatio.Y + positionOffset.Y;
            child.SetPosition(x, y);

            return base.AddChild(child, z, child.Tag);
        }
Пример #3
0
        public void AddAction(Action action, CocosNode target)
        {
            if (action == null) {
                throw new ArgumentNullException("action");
            }
            if (target == null) {
                throw new ArgumentNullException("target");
            }

            HashElement element = null;
            if (_hash.ContainsKey(target)) {
                element = _hash[target];
            } else {
                element = new HashElement();
                element.Target = target;
                _hash.Add(target, element);
            }

            element.Actions.Add(action);
            action.Target = target;
            action.Start();
        }
Пример #4
0
        private void InsertChild(CocosNode child, int z)
        {
            int i = 0;
            bool added = false;

            foreach (CocosNode node in _children) {
                if (node.ZOrder > z) {
                    added = true;
                    _children.Insert(i, child);
                    break;
                }
                ++i;
            }

            if (!added) {
                _children.Add(child);
            }

            child._zorder = z;
        }
Пример #5
0
        private void DetachChild(CocosNode child, bool cleanup)
        {
            if (IsRunning) {
                child.OnExit();
            }

            if (cleanup) {
                child.CleanUp();
            }

            child.Parent = null;

            _children.Remove(child);
        }
Пример #6
0
 //        private void ReorderChild(CocosNode child, int z) {
 //            if (child == null) {
 //                throw new ArgumentNullException("child");
 //            }
 //            
 //            _children.Remove(child);
 //            InsertChild(child, z);
 //        }
 public virtual void RemoveChild(CocosNode child, bool cleanup)
 {
     if (child != null) {
         if (Children.Contains(child)) {
             DetachChild(child, cleanup);
         }
     }
 }
Пример #7
0
        public virtual CocosNode AddChild(CocosNode child, int z, int tag)
        {
            if (child == null) {
                throw new ArgumentNullException("child");
            }
            if (child.Parent != null) {
                throw new ArgumentException("Child already has a parent", "child");
            }

            child.Tag = tag;

            InsertChild(child, z);
            child.Parent = this;

            if (IsRunning) {
                child.OnEnter();
            }

            return this;
        }
Пример #8
0
 public CocosNode AddChild(CocosNode child, int zOrder)
 {
     return AddChild(child, zOrder, child.Tag);
 }
Пример #9
0
 public CocosNode AddChild(CocosNode child)
 {
     return AddChild(child, child.ZOrder, child.Tag);
 }
Пример #10
0
        public override CocosNode AddChild(CocosNode child, int z, int tag)
        {
            if (!(child is MenuItem)) {
                throw new ArgumentException("Can only add menu items to a menu", "child");
            }

            return base.AddChild(child, z, tag);
        }
Пример #11
0
 public void RemoveAllActionsForTarget(CocosNode target)
 {
     if (target != null && _hash.ContainsKey(target)) {
         _hash.Remove(target);
     }
 }
Пример #12
0
            public NodeBox(PointF ratio, PointF offset, CocosNode child)
            {
                if (child == null) {
                    throw new ArgumentNullException("child");
                }

                Ratio = ratio;
                Offset = offset;
                Child = child;
            }
Пример #13
0
 public override CocosNode AddChild(CocosNode child, int z, int tag)
 {
     throw new Exception("Use AddChild(CocosNode node, int z, PointF parallaxRatio, PointF positionOffset) instead");
 }
Пример #14
0
 private void Callback3(CocosNode sender, object data)
 {
     Console.WriteLine("callback 3 called from:{0} with data:{1}", sender, data);
     SizeF s = Director.Instance.WinSize;
     Label label = new Label("callback 3 called", "Marker Felt", 16);
     label.SetPosition(s.Width / 4 * 3, s.Height / 2);
     AddChild(label, 4);
 }
Пример #15
0
 private void Callback2(CocosNode sender)
 {
     Console.WriteLine("callback 2 called from: " + sender.ToString());
     SizeF s = Director.Instance.WinSize;
     Label label = new Label("callback 2 called", "Marker Felt", 16);
     label.SetPosition(s.Width / 4 * 2, s.Height / 2);
     AddChild(label, 4);
 }