Пример #1
0
        public CCLayer SwitchTo(int index)
        {
            if (index < NoLayer || index >= Layers.Count)
            {
                return(null);
            }

            CCLayer outLayer = EnabledLayerIndex != NoLayer ? Layers[EnabledLayerIndex] : null;
            CCLayer inLayer  = index != NoLayer ? Layers[index] : null;

            if (outLayer != null)
            {
                if (OutAction != null)
                {
                    outLayer.RunAction(new CCSequence(
                                           OutAction,
                                           new CCCallFunc(() => { outLayer.Visible = false; })
                                           )
                                       );
                }
                else
                {
                    outLayer.Visible = false;
                }
            }


            if (inLayer != null)
            {
                if (InAction != null)
                {
                    inLayer.RunAction(
                        new CCSequence(
                            InAction,
                            new CCCallFunc(() => { inLayer.Visible = true; })
                            )
                        );
                }
                else
                {
                    inLayer.Visible = true;
                }
            }

            EnabledLayerIndex = index;

            if (EnabledLayerIndex != NoLayer)
            {
                ShowFirstLayerOnEnter = false;
            }

            return(inLayer);
        }
Пример #2
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = Layer.VisibleBoundsWorldspace.Size;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);
            var rgba = new CCLayer();
            rgba.IsColorCascaded = true;
            rgba.IsOpacityCascaded = true;
            AddChild(rgba);

            CCLog.Log("S9CascadeOpacityAndColor ...");

            var blocks_scaled_with_insets = CCScale9Sprite.SpriteWithFrameName("blocks9r.png");
            CCLog.Log("... created");

            blocks_scaled_with_insets.Position = new CCPoint(x, y);
            CCLog.Log("... setPosition");

            rgba.AddChild(blocks_scaled_with_insets);
            var actions = new CCSequence(new CCFadeIn(1),
                                         new CCTintTo(1, 0, 255, 0),
                                         new CCTintTo(1, 255, 255, 255),
                                         new CCFadeOut(1));
            var repeat = new CCRepeatForever(actions);
            rgba.RunAction(repeat);
            CCLog.Log("AddChild");

            CCLog.Log("... S9CascadeOpacityAndColor done.");
        }
Пример #3
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize s = Layer.VisibleBoundsWorldspace.Size;

            var layer1 = new CCLayerColor(new CCColor4B(0xFF, 0xFF, 0x00, 0x80));
            layer1.IgnoreAnchorPointForPosition = false;
            layer1.Position = (new CCPoint(s.Width / 2, s.Height / 2));
            layer1.ChildClippingMode = CCClipMode.Bounds;
            AddChild(layer1, 1);

            s = layer1.ContentSize;

            m_pInnerLayer = new CCLayerColor(new CCColor4B(0xFF, 0x00, 0x00, 0x80));
            m_pInnerLayer.IgnoreAnchorPointForPosition = false;
            m_pInnerLayer.Position = (new CCPoint(s.Width / 2, s.Height / 2));
            m_pInnerLayer.ChildClippingMode = CCClipMode.Bounds;
            
            layer1.AddChild(m_pInnerLayer, 1);
            
            //
            // Add two labels using BM label class
            // CCLabelBMFont
            CCLabelBMFont label1 = new CCLabelBMFont("LABEL1", "fonts/konqa32.fnt");
            label1.Position = new CCPoint(m_pInnerLayer.ContentSize.Width, m_pInnerLayer.ContentSize.Height * 0.75f);
            m_pInnerLayer.AddChild(label1);
            
            CCLabelBMFont label2 = new CCLabelBMFont("LABEL2", "fonts/konqa32.fnt");
            label2.Position = new CCPoint(0, m_pInnerLayer.ContentSize.Height * 0.25f);
            m_pInnerLayer.AddChild(label2);


            CCScaleTo scaleTo2 = new CCScaleTo(runTime * 0.25f, 3.0f);
            CCScaleTo scaleTo3 = new CCScaleTo(runTime * 0.25f, 1.0f);

            m_pInnerLayer.RepeatForever(scaleTo2, scaleTo3);


            CCFiniteTimeAction seq = new CCRepeatForever(
                new CCSequence(scaleTo2, scaleTo3)
                );

            m_pInnerLayer.RunAction(seq);

            CCSize size = Layer.VisibleBoundsWorldspace.Size;

            var move1 = new CCMoveTo(2, new CCPoint(size.Width / 2, size.Height));
            var move2 = new CCMoveTo(2, new CCPoint(size.Width, size.Height / 2));
            var move3 = new CCMoveTo(2, new CCPoint(size.Width / 2, 0));
            var move4 = new CCMoveTo(2, new CCPoint(0, size.Height / 2));

            layer1.RunAction(new CCRepeatForever(new CCSequence(move1, move2, move3, move4)));
        }
Пример #4
0
        /// <summary>
        /// Swtich to the given index layer and use the given action after the layer is
        /// added to the parent. The parameter can be the index or it can be the tag of the layer.
        /// </summary>
        /// <param name="n">Send in NoLayer to hide all multiplexed layers. Otherwise, send in a tag or the logical index of the
        /// layer to show.</param>
        /// <returns>The layer that is going to be shown. This can return null if the SwitchTo layer is NoLayer</returns>
        public CCLayer SwitchTo(int n)
        {
            if (n != NoLayer)
            {
                if (EnabledLayer == n || EnabledLayer == (n + TagOffsetForUniqueness))
                {
                    if (EnabledLayer == NoLayer)
                    {
                        return(null);
                    }
                    return(Layers[EnabledLayer]);
                }
            }

            if (EnabledLayer != NoLayer)
            {
                CCLayer outLayer = null;
                if (Layers.ContainsKey(EnabledLayer))
                {
                    outLayer = Layers[EnabledLayer];
                    if (OutAction != null)
                    {
                        outLayer.RunAction(
                            new CCSequence(
                                (CCFiniteTimeAction)OutAction,
                                new CCCallFunc(() => RemoveChild(outLayer, true))
                                )
                            );
                    }
                    else
                    {
                        RemoveChild(outLayer, true);
                    }
                }
                // We have no enabled layer at this point
                EnabledLayer = NoLayer;
            }

            // When NoLayer, the multiplexer shows nothing.
            if (n == NoLayer)
            {
                ShowFirstLayerOnEnter = false;
                return(null);
            }

            if (!Layers.ContainsKey(n))
            {
                int f = n + TagOffsetForUniqueness;
                if (Layers.ContainsKey(f))
                {
                    n = f;
                }
                else
                {
                    // Invalid index - layer not found
                    return(null);
                }
            }

            // Set the active layer
            AddChild(Layers[n]);
            EnabledLayer = n;

            if (InAction != null)
            {
                Layers[n].RunAction(InAction);
            }

            return(Layers[EnabledLayer]);
        }