Пример #1
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                CCNode layer = new CCNode ();
                layer.Position = new CCPoint(screenSize.Width / 2, screenSize.Height / 2);
                AddChild(layer, 1);

                float layer_width = 0.0f;

                // Add the black background for the text
                CCScale9Sprite background = new CCScale9SpriteFile("extensions/buttonBackground");
                background.ContentSize = new CCSize(80, 50);
                background.Position = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
                layer.AddChild(background);

                layer_width += background.ContentSize.Width;

                m_pDisplayValueLabel = new CCLabelTTF("#color", "Marker Felt", 30);

                m_pDisplayValueLabel.Position = background.Position;
                layer.AddChild(m_pDisplayValueLabel);

                // Create the switch
                CCControlSwitch switchControl = new CCControlSwitch
                    (
                        new CCSprite("extensions/switch-mask"),
                        new CCSprite("extensions/switch-on"),
                        new CCSprite("extensions/switch-off"),
                        new CCSprite("extensions/switch-thumb"),
                        new CCLabelTTF("On", "Arial-BoldMT", 16),
                        new CCLabelTTF("Off", "Arial-BoldMT", 16)
                    );
                switchControl.Position = new CCPoint(layer_width + 10 + switchControl.ContentSize.Width / 2, 0);
                layer.AddChild(switchControl);

                switchControl.AddTargetWithActionForControlEvents(this, valueChanged, CCControlEvent.ValueChanged);

                // Set the layer size
                layer.ContentSize = new CCSize(layer_width, 0);
                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

                // Update the value label
                valueChanged(switchControl, CCControlEvent.ValueChanged);
                return true;
            }
            return false;
        }
Пример #2
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;
        }
Пример #3
0
        public override bool Init()
        {
            if (base.Init())
            {
                // Get the sceensize
                CCSize screensize = CCDirector.SharedDirector.WinSize;

                var pBackItem = new CCMenuItemFont("Back", toExtensionsMainLayer);
                pBackItem.Position = new CCPoint(screensize.Width - 50, 25);
                var pBackMenu = new CCMenu(pBackItem);
                pBackMenu.Position =  CCPoint.Zero;
                AddChild(pBackMenu, 10);

                // Add the generated background
                var background = new CCSprite("extensions/background");
                background.Position = new CCPoint(screensize.Width / 2, screensize.Height / 2);
                AddChild(background);

                // Add the ribbon
                var ribbon = new CCScale9SpriteFile("extensions/ribbon", new CCRect(1, 1, 48, 55));
                ribbon.ContentSize = new CCSize(screensize.Width, 57);
                ribbon.Position = new CCPoint(screensize.Width / 2.0f, screensize.Height - ribbon.ContentSize.Height / 2.0f);
                AddChild(ribbon);

                // Add the title
                setSceneTitleLabel(new CCLabelTTF("Title", "arial", 12));
                m_pSceneTitleLabel.Position = new CCPoint(screensize.Width / 2, screensize.Height - m_pSceneTitleLabel.ContentSize.Height / 2 - 5);
                AddChild(m_pSceneTitleLabel, 1);

                // Add the menu
                var item1 = new CCMenuItemImage("Images/b1", "Images/b2", previousCallback);
                var item2 = new CCMenuItemImage("Images/r1", "Images/r2", restartCallback);
                var item3 = new CCMenuItemImage("Images/f1", "Images/f2", nextCallback);

                var menu = new CCMenu(item1, item3, item2);
                menu.Position = CCPoint.Zero;
                item1.Position = new CCPoint(screensize.Width / 2 - 100, 37);
                item2.Position = new CCPoint(screensize.Width / 2, 35);
                item3.Position = new CCPoint(screensize.Width / 2 + 100, 37);

                AddChild(menu ,1);

                return true;
            }
            return false;
        }
Пример #4
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;
        }
Пример #5
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                var layer = new CCNode ();
                AddChild(layer, 1);

                int space = 10; // px

                float max_w = 0, max_h = 0;
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {

                        // Add the buttons
                        var button = standardButtonWithTitle(Random.Next(30).ToString());
                        button.SetAdjustBackgroundImage(false);  // Tells the button that the background image must not be adjust
                                                            // It'll use the prefered size of the background image
                        button.Position = new CCPoint(button.ContentSize.Width / 2 + (button.ContentSize.Width + space) * i,
                                               button.ContentSize.Height / 2 + (button.ContentSize.Height + space) * j);
                        layer.AddChild(button);

                        max_w = Math.Max(button.ContentSize.Width * (i + 1) + space * i, max_w);
                        max_h = Math.Max(button.ContentSize.Height * (j + 1) + space * j, max_h);
                    }
                }

                layer.AnchorPoint = new CCPoint (0.5f, 0.5f);
                layer.ContentSize = new CCSize(max_w, max_h);
                layer.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);

                // Add the black background
                var backgroundButton = new CCScale9SpriteFile("extensions/buttonBackground");
                backgroundButton.ContentSize = new CCSize(max_w + 14, max_h + 14);
                backgroundButton.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(backgroundButton);
                return true;
            }
            return false;
        }
Пример #6
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;
        }
Пример #7
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                // Defines an array of title to create buttons dynamically
                var stringArray = new[] {
                    "Inset",
                    "Inset",
                    "Inset"
                };

                CCNode layer = new CCNode ();
                AddChild(layer, 1);

                float total_width = 0, height = 0;

                // For each title in the array
                object pObj = null;
                foreach (var title in stringArray)
                {
                    // Creates a button with this string as title
                    CCControlButton button = insetButtonWithTitle(title, new CCRect(5, 5, 5, 5));
                    button.Position = new CCPoint(total_width + button.ContentSize.Width / 2, button.ContentSize.Height / 2);
                    layer.AddChild(button);

                    // Compute the size of the layer
                    height = button.ContentSize.Height;
                    total_width += button.ContentSize.Width;
                }

                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);
                layer.ContentSize = new CCSize(total_width, height);
                layer.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);

                // Add the black background
                var background = new CCScale9SpriteFile("extensions/buttonBackground");
                background.ContentSize = new CCSize(total_width + 14, height + 14);
                background.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(background);
                return true;
            }
            return false;
        }