Ejemplo n.º 1
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                // Add a label in which the button events will be displayed
                setDisplayValueLabel(new CCLabelTTF("No Event", "Marker Felt", 32));
                m_pDisplayValueLabel.AnchorPoint = new CCPoint(0.5f, -1);
                m_pDisplayValueLabel.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(m_pDisplayValueLabel, 1);

                // Add the button
                var backgroundButton = new CCScale9SpriteFile("extensions/button");
                var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");

                var titleButton = new CCLabelTTF("Touch Me!", "Marker Felt", 30);

                titleButton.Color = new CCColor3B(159, 168, 176);

                var controlButton = new CCControlButton(titleButton, backgroundButton);
                controlButton.SetBackgroundSpriteForState(backgroundHighlightedButton, CCControlState.Highlighted);
                controlButton.SetTitleColorForState(CCTypes.CCWhite, CCControlState.Highlighted);

                controlButton.AnchorPoint = new CCPoint(0.5f, 1);
                controlButton.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(controlButton, 1);

                // Add the black background
                var background = new CCScale9SpriteFile("extensions/buttonBackground");
                background.ContentSize = new CCSize(300, 170);
                background.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(background);

                // Sets up event handlers
                controlButton.AddTargetWithActionForControlEvent(this, touchDownAction, CCControlEvent.TouchDown);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragInsideAction, CCControlEvent.TouchDragInside);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragOutsideAction, CCControlEvent.TouchDragOutside);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragEnterAction, CCControlEvent.TouchDragEnter);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragExitAction, CCControlEvent.TouchDragExit);
                controlButton.AddTargetWithActionForControlEvent(this, touchUpInsideAction, CCControlEvent.TouchUpInside);
                controlButton.AddTargetWithActionForControlEvent(this, touchUpOutsideAction, CCControlEvent.TouchUpOutside);
                controlButton.AddTargetWithActionForControlEvent(this, touchCancelAction, CCControlEvent.TouchCancel);
                return true;
            }
            return false;
        }
Ejemplo n.º 2
0
 public static new CCControlButton Create()
 {
     var pControlButton = new CCControlButton();
     return pControlButton;
 }
Ejemplo n.º 3
0
        public CCControlButton standardButtonWithTitle(string title)
        {
            /** Creates and return a button with a default background and title color. */
            var backgroundButton = new CCScale9SpriteFile("extensions/button");
            backgroundButton.PreferredSize = new CCSize(45, 45);  // Set the prefered size
            var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");
            backgroundHighlightedButton.PreferredSize = new CCSize(45, 45);  // Set the prefered size

            var titleButton = new CCLabelTTF(title, "Marker Felt", 30);

            titleButton.Color = new CCColor3B(159, 168, 176);

            var button = new CCControlButton(titleButton, backgroundButton);
            button.SetBackgroundSpriteForState(backgroundHighlightedButton, CCControlState.Highlighted);
            button.SetTitleColorForState(CCTypes.CCWhite, CCControlState.Highlighted);

            return button;
        }
Ejemplo n.º 4
0
        public CCControlButton insetButtonWithTitle(string title, CCRect inset)
        {
            /** Creates and return a button with a default background and title color. */
            var backgroundButton = new CCScale9SpriteFile("extensions/button");
            var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");
            backgroundButton.CapInsets = inset;
            backgroundHighlightedButton.CapInsets = inset;

            var titleButton = new CCLabelTTF(title, "Marker Felt", 30);

            titleButton.Color = new CCColor3B(159, 168, 176);

            var button = new CCControlButton(titleButton, backgroundButton);
            button.SetBackgroundSpriteForState(backgroundHighlightedButton, CCControlState.Highlighted);
            button.SetTitleColorForState(CCTypes.CCWhite, CCControlState.Highlighted);

            return button;
        }
Ejemplo n.º 5
0
 public static CCControlButton Create(CCScale9Sprite sprite)
 {
     var pRet = new CCControlButton();
     pRet.InitWithBackgroundSprite(sprite);
     return pRet;
 }
Ejemplo n.º 6
0
 public static CCControlButton Create(string title, string fontName, float fontSize)
 {
     var pRet = new CCControlButton();
     pRet.InitWithTitleAndFontNameAndFontSize(title, fontName, fontSize);
     return pRet;
 }
Ejemplo n.º 7
0
 public static CCControlButton Create(CCNode label, CCScale9Sprite backgroundSprite)
 {
     var pRet = new CCControlButton();
     pRet.InitWithLabelAndBackgroundSprite(label, backgroundSprite);
     return pRet;
 }