Beispiel #1
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(" ", "Arial", 12));
				m_pSceneTitleLabel.Position = new CCPoint(screensize.Width / 2, screensize.Height - m_pSceneTitleLabel.ContentSize.Height / 2 - 5);
				AddChild(m_pSceneTitleLabel, 1);

                // Add the subtitle
                setSceneSubtitleLabel(new CCLabelTTF(" ", "Arial", 12));
			    m_pSceneSubtitleLabel.Position = new CCPoint(screensize.Width / 2,
			                                                 screensize.Height - m_pSceneTitleLabel.ContentSize.Height -
			                                                 m_pSceneSubtitleLabel.ContentSize.Height / 2 - 10);
                AddChild(m_pSceneSubtitleLabel, 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;

		}
        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;

                // Create the colour picker
                CCControlColourPicker colourPicker = new CCControlColourPicker();
                colourPicker.Color = new CCColor3B(37, 46, 252);
                colourPicker.Position = new CCPoint(colourPicker.ContentSize.Width / 2, 0);

                // Add it to the layer
                layer.AddChild(colourPicker);

                // Add the target-action pair
                colourPicker.AddTargetWithActionForControlEvents(this, ColourValueChanged,
                                                                  CCControlEvent.ValueChanged);


                layer_width += colourPicker.ContentSize.Width;

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

                layer_width += background.ContentSize.Width;

                _colorLabel = new CCLabelTTF("#color", "Arial", 26);

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

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

                // Update the color text
                ColourValueChanged(colourPicker, CCControlEvent.ValueChanged);
                return true;
            }
            return false;
        }
        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", "Arial", 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", 16),
                        new CCLabelTTF("Off", "Arial", 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;
        }
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

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

                double layer_width = 0;

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

                layer_width += background.ContentSize.Width;

                DisplayValueLabel = new CCLabelTTF("", "Arial", 30);

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

                // Add the slider
                var potentiometer = new CCControlPotentiometer("extensions/potentiometerTrack.png"
                                                               ,
                                                               "extensions/potentiometerProgress.png"
                                                               , "extensions/potentiometerButton.png");
                potentiometer.Position = new CCPoint((float) layer_width + 10 + potentiometer.ContentSize.Width / 2, 0);

                // When the value of the slider will change, the given selector will be call
                potentiometer.AddTargetWithActionForControlEvents(this, ValueChanged, CCControlEvent.ValueChanged);

                layer.AddChild(potentiometer);

                layer_width += potentiometer.ContentSize.Width;

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

                // Update the value label
                ValueChanged(potentiometer, CCControlEvent.ValueChanged);
                return true;
            }
            return false;
        }
		/** Creates and return a button with a default background and title color. */
		public CCControlButton standardButtonWithTitle(string title)
		{
			/** Creates and return a button with a default background and title color. */
			var backgroundButton = new CCScale9SpriteFile("extensions/button");
			var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");
    
			var titleButton = new CCLabelTTF(title, "Arial", 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;
		}
		public override bool Init()
		{
			if (base.Init())
			{
				CCSize screenSize = CCDirector.SharedDirector.WinSize;
        
				// Defines an array of title to create buttons dynamically
				var stringArray = new[] {
					"Hello",
					"Variable",
					"Size",
					"!"
				};
        
				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
					var button = standardButtonWithTitle(title);
					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;
		}
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                var layer = new CCNode();
                layer.Position = screenSize.Center;
                AddChild(layer, 1);

                float layer_width = 0;

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

                DisplayValueLabel = new CCLabelTTF("0", "Arial", 26);

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

                layer_width += background.ContentSize.Width;

                CCControlStepper stepper = MakeControlStepper();
                stepper.Position = new CCPoint(layer_width + 10 + stepper.ContentSize.Width / 2, 0);
                stepper.AddTargetWithActionForControlEvents(this, ValueChanged,
                                                            CCControlEvent.ValueChanged);
                layer.AddChild(stepper);

                layer_width += stepper.ContentSize.Width;

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

                // Update the value label
                ValueChanged(stepper, CCControlEvent.ValueChanged);
                return true;
            }
            return false;
        }
        public CCControlButton standardButtonWithTitle(string title)
        {
            _TheTexture = CCTextureCache.SharedTextureCache.AddImage("extensions/button");
            /** Creates and return a button with a default background and title color. */
            var backgroundButton = new CCScale9SpriteFile("extensions/button");
            backgroundButton.PreferredSize = new CCSize(55, 55);  // Set the prefered size
            var backgroundHighlightedButton = new CCScale9SpriteFile("extensions/buttonHighlighted");
            backgroundHighlightedButton.PreferredSize = new CCSize(55, 55);  // Set the prefered size

            var titleButton = new CCLabelTTF(title, "Arial", 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;
        }
        /*
         * This is a test of the texture reinit on the control button.
         */
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

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

                CreateTheButtons();

                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;
        }
		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(CCRandom.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;
		}
		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", "Arial", 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!", "Arial", 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;
		}