Пример #1
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);

            CCLog.Log("S9BatchNodeBasic ...");

            var batchNode = new CCSpriteBatchNode("Images/blocks9.png");
            //batchNode.AnchorPoint = new CCPoint(0.5f, 0.5f);
            CCLog.Log("batchNode created with : Images/blocks9.png");

            var blocks = new CCScale9Sprite();
            CCLog.Log("... created");

            blocks.UpdateWithBatchNode(batchNode, new CCRect(0, 0, 96, 96), false, new CCRect(0, 0, 96, 96));
            CCLog.Log("... updateWithBatchNode");

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

            AddChild(blocks);
            CCLog.Log("AddChild");

            CCLog.Log("... S9BatchNodeBasic done.");
        }
Пример #2
0
        /**
         * Sets the background sprite to use for the specified button state.
         *
         * @param sprite The background sprite to use for the specified state.
         * @param state The state that uses the specified image. The values are described
         * in "CCControlState".
         */

        public virtual void SetBackgroundSpriteForState(CCScale9Sprite sprite, CCControlState state)
        {
            CCSize oldPreferredSize = m_preferredSize;

            CCScale9Sprite previousBackgroundSprite;

            if (m_backgroundSpriteDispatchTable.TryGetValue(state, out previousBackgroundSprite))
            {
                RemoveChild(previousBackgroundSprite, true);
                m_backgroundSpriteDispatchTable.Remove(state);
            }

            m_backgroundSpriteDispatchTable.Add(state, sprite);
            sprite.Visible     = false;
            sprite.AnchorPoint = new CCPoint(0.5f, 0.5f);
            AddChild(sprite);

            if (m_preferredSize.Width != 0 || m_preferredSize.Height != 0)
            {
                if (oldPreferredSize.Equals(m_preferredSize))
                {
                    // Force update of preferred size
                    sprite.PreferredSize = new CCSize(oldPreferredSize.Width + 1, oldPreferredSize.Height + 1);
                }

                sprite.PreferredSize = m_preferredSize;
            }

            // If the current state if equal to the given state we update the layout
            if (State == state)
            {
                NeedsLayout();
            }
        }
Пример #3
0
 protected virtual bool InitWithBackgroundSprite(CCScale9Sprite sprite)
 {
     CCLabelTTF label = new CCLabelTTF("", "arial", 30);
     return InitWithLabelAndBackgroundSprite(label, sprite);
 }
Пример #4
0
 public CCControlButton(CCNode label, CCScale9Sprite backgroundSprite)
 {
     InitWithLabelAndBackgroundSprite(label, backgroundSprite);
 }
Пример #5
0
        public virtual bool InitWithLabelAndBackgroundSprite(CCNode node, CCScale9Sprite backgroundSprite)
        {
            if (base.Init())
            {
                Debug.Assert(node != null, "Label must not be nil.");
                var label = node as ICCLabelProtocol;
                var rgbaLabel = node as ICCRGBAProtocol;
                Debug.Assert(backgroundSprite != null, "Background sprite must not be nil.");
                Debug.Assert(label != null || rgbaLabel != null || backgroundSprite != null);

                m_bParentInited = true;

                // Initialize the button state tables
                m_titleDispatchTable = new Dictionary<CCControlState, string>();
                m_titleColorDispatchTable = new Dictionary<CCControlState, CCColor3B>();
                m_titleLabelDispatchTable = new Dictionary<CCControlState, CCNode>();
                m_backgroundSpriteDispatchTable = new Dictionary<CCControlState, CCScale9Sprite>();

                TouchEnabled = true;
                m_isPushed = false;
                m_zoomOnTouchDown = true;

                m_currentTitle = null;

                // Adjust the background image by default
                SetAdjustBackgroundImage(true);
                PreferredSize = CCSize.Zero;
                // Zooming button by default
                m_zoomOnTouchDown = true;

                // Set the default anchor point
                IgnoreAnchorPointForPosition = false;
                AnchorPoint = new CCPoint(0.5f, 0.5f);

                // Set the nodes
                TitleLabel = node;
                BackgroundSprite = backgroundSprite;

                // Set the default color and opacity
                Color = new CCColor3B(255, 255, 255);
                Opacity = 255;
                IsOpacityModifyRGB = true;

                // Initialize the dispatch table

                string tempString = label.Text;
                //tempString->autorelease();
                SetTitleForState(tempString, CCControlState.Normal);
                SetTitleColorForState(rgbaLabel.Color, CCControlState.Normal);
                SetTitleLabelForState(node, CCControlState.Normal);
                SetBackgroundSpriteForState(backgroundSprite, CCControlState.Normal);

                LabelAnchorPoint = new CCPoint(0.5f, 0.5f);

                NeedsLayout();

                return true;
            }
            //couldn't init the CCControl
            return false;
        }
Пример #6
0
 public CCControlButton(CCScale9Sprite sprite)
 {
     InitWithBackgroundSprite(sprite);
 }
Пример #7
0
        protected virtual bool InitWithBackgroundSprite(CCScale9Sprite sprite)
        {
            CCLabelTTF label = new CCLabelTTF("", "arial", 30);

            return(InitWithLabelAndBackgroundSprite(label, sprite));
        }
Пример #8
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);

            CCLog.Log("S9BatchNodeScaleWithCapInsets ...");

            var batchNode_scaled_with_insets = new CCSpriteBatchNode("Images/blocks9.png");
            CCLog.Log("batchNode_scaled_with_insets created with : Images/blocks9.png");

            var blocks_scaled_with_insets = new CCScale9Sprite();
            CCLog.Log("... created");

            blocks_scaled_with_insets.UpdateWithBatchNode(batchNode_scaled_with_insets, new CCRect(0, 0, 96, 96), false,
                                                          new CCRect(32, 32, 32, 32));
            CCLog.Log("... updateWithBatchNode");

            blocks_scaled_with_insets.ContentSize = new CCSize(96 * 4.5f, 96 * 2.5f);
            CCLog.Log("... setContentSize");

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

            AddChild(blocks_scaled_with_insets);
            CCLog.Log("AddChild");

            CCLog.Log("... S9BatchNodeScaleWithCapInsets done.");
        }
Пример #9
0
        public virtual bool InitWithLabelAndBackgroundSprite(CCNode node, CCScale9Sprite backgroundSprite)
        {
            if (base.Init())
            {
                Debug.Assert(node != null, "Label must not be nil.");
                var label     = node as ICCLabelProtocol;
                var rgbaLabel = node as ICCRGBAProtocol;
                Debug.Assert(backgroundSprite != null, "Background sprite must not be nil.");
                Debug.Assert(label != null || rgbaLabel != null || backgroundSprite != null);

                m_bParentInited = true;

                // Initialize the button state tables
                m_titleDispatchTable            = new Dictionary <CCControlState, string>();
                m_titleColorDispatchTable       = new Dictionary <CCControlState, CCColor3B>();
                m_titleLabelDispatchTable       = new Dictionary <CCControlState, CCNode>();
                m_backgroundSpriteDispatchTable = new Dictionary <CCControlState, CCScale9Sprite>();

                TouchEnabled      = true;
                m_isPushed        = false;
                m_zoomOnTouchDown = true;

                m_currentTitle = null;

                // Adjust the background image by default
                SetAdjustBackgroundImage(true);
                PreferredSize = CCSize.Zero;
                // Zooming button by default
                m_zoomOnTouchDown = true;

                // Set the default anchor point
                IgnoreAnchorPointForPosition = false;
                AnchorPoint = new CCPoint(0.5f, 0.5f);

                // Set the nodes
                TitleLabel       = node;
                BackgroundSprite = backgroundSprite;

                // Set the default color and opacity
                Color              = new CCColor3B(255, 255, 255);
                Opacity            = 255;
                IsOpacityModifyRGB = true;

                // Initialize the dispatch table

                string tempString = label.Label;
                //tempString->autorelease();
                SetTitleForState(tempString, CCControlState.Normal);
                SetTitleColorForState(rgbaLabel.Color, CCControlState.Normal);
                SetTitleLabelForState(node, CCControlState.Normal);
                SetBackgroundSpriteForState(backgroundSprite, CCControlState.Normal);

                LabelAnchorPoint = new CCPoint(0.5f, 0.5f);

                NeedsLayout();

                return(true);
            }
            //couldn't init the CCControl
            return(false);
        }
Пример #10
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);

            CCLog.Log("S9FrameNameSpriteSheet ...");

            var blocks = new CCScale9Sprite();
            blocks.InitWithSpriteFrameName("blocks9.png");
            CCLog.Log("... created");

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

            AddChild(blocks);
            CCLog.Log("AddChild");

            CCLog.Log("... S9FrameNameSpriteSheet done.");
        }
Пример #11
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);
            var rgba = new CCLayerRGBA();
            rgba.CascadeColorEnabled = true;
            rgba.CascadeOpacityEnabled = true;
            AddChild(rgba);

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

            var blocks_scaled_with_insets = new CCScale9Sprite();
            blocks_scaled_with_insets.InitWithSpriteFrameName("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.");
        }
Пример #12
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);

            CCLog.Log("Scale9FrameNameSpriteSheetRotatedSetCapInsetLater ...");

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

            blocks_scaled_with_insets.InsetLeft = 32;
            blocks_scaled_with_insets.InsetRight = 32;

            blocks_scaled_with_insets.PreferredSize = new CCSize(32 * 5.5f, 32 * 4);
            blocks_scaled_with_insets.Position = new CCPoint(x, y);
            CCLog.Log("... setPosition");

            AddChild(blocks_scaled_with_insets);
            CCLog.Log("AddChild");

            CCLog.Log("... Scale9FrameNameSpriteSheetRotatedSetCapInsetLater done.");
        }
Пример #13
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);

            CCLog.Log("S9FrameNameSpriteSheetRotatedInsetsScaled ...");

            var blocks_scaled_with_insets = new CCScale9Sprite();
            blocks_scaled_with_insets.InitWithSpriteFrameName("blocks9.png", new CCRect(32, 32, 32, 32));
            CCLog.Log("... created");

            blocks_scaled_with_insets.ContentSize = new CCSize(96 * 4.5f, 96 * 2.5f);
            CCLog.Log("... setContentSize");

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

            AddChild(blocks_scaled_with_insets);
            CCLog.Log("AddChild");

            CCLog.Log("... S9FrameNameSpriteSheetRotatedInsetsScaled done.");
        }
Пример #14
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("Images/ui.plist", "Images/ui.png", "");

            float x = winSize.Width / 4;
            float y = 0 + (winSize.Height / 2);

            CCLog.Log("S9_TexturePacker ...");

            var s = new CCScale9Sprite();
            s.InitWithSpriteFrameName("button_normal.png");
            CCLog.Log("... created");

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

            s.ContentSize = new CCSize(14 * 16, 10 * 16);
            CCLog.Log("... setContentSize");

            AddChild(s);
            CCLog.Log("AddChild");

            x = winSize.Width * 3 / 4;

            var s2 = new CCScale9Sprite();
            s2.InitWithSpriteFrameName("button_actived.png");
            CCLog.Log("... created");

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

            s2.ContentSize = new CCSize(14 * 16, 10 * 16);
            CCLog.Log("... setContentSize");

            AddChild(s2);
            CCLog.Log("AddChild");

            CCLog.Log("... S9_TexturePacker done.");
        }
Пример #15
0
 public CCControlButton(CCScale9Sprite sprite)
 {
     InitWithBackgroundSprite(sprite);
 }
Пример #16
0
 public CCControlButton(CCNode label, CCScale9Sprite backgroundSprite)
 {
     InitWithLabelAndBackgroundSprite(label, backgroundSprite);
 }
Пример #17
0
        /**
        * Sets the background sprite to use for the specified button state.
        *
        * @param sprite The background sprite to use for the specified state.
        * @param state The state that uses the specified image. The values are described
        * in "CCControlState".
        */

        public virtual void SetBackgroundSpriteForState(CCScale9Sprite sprite, CCControlState state)
        {
            CCSize oldPreferredSize = m_preferredSize;

            CCScale9Sprite previousBackgroundSprite;
            if (m_backgroundSpriteDispatchTable.TryGetValue(state, out previousBackgroundSprite))
            {
                RemoveChild(previousBackgroundSprite, true);
                m_backgroundSpriteDispatchTable.Remove(state);
            }

            m_backgroundSpriteDispatchTable.Add(state, sprite);
            sprite.Visible = false;
            sprite.AnchorPoint = new CCPoint(0.5f, 0.5f);
            AddChild(sprite);

            if (m_preferredSize.Width != 0 || m_preferredSize.Height != 0)
            {
                if (oldPreferredSize.Equals(m_preferredSize))
                {
                    // Force update of preferred size
                    sprite.PreferredSize = new CCSize(oldPreferredSize.Width + 1, oldPreferredSize.Height + 1);
                }

                sprite.PreferredSize = m_preferredSize;
            }

            // If the current state if equal to the given state we update the layout
            if (State == state)
            {
                NeedsLayout();
            }
        }
Пример #18
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);

            CCLog.Log("S9FrameNameSpriteSheetRotatedScaledNoInsets ...");

            var blocks_scaled = new CCScale9Sprite();
            blocks_scaled.InitWithSpriteFrameName("blocks9r.png");
            CCLog.Log("... created");

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

            blocks_scaled.ContentSize = new CCSize(96 * 4, 96 * 2);
            CCLog.Log("... setContentSize");

            AddChild(blocks_scaled);
            CCLog.Log("AddChild");

            CCLog.Log("... S9FrameNameSpriteSheetRotatedScaledNoInsets done.");
        }