示例#1
0
		/** 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(CCColor3B.White, CCControlState.Highlighted);
    
			return button;
		}
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

            // Add a label in which the button events will be displayed
            DisplayValueLabel = new CCLabel("No Event", "Arial", 28, CCLabelFormat.SpriteFont);
            DisplayValueLabel.AnchorPoint = new CCPoint(0.5f, -0.5f);
            DisplayValueLabel.Position = screenSize.Center;
            AddChild(DisplayValueLabel, 1);

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

            var titleButton = new CCLabel("Touch Me!", "Arial", 30, CCLabelFormat.SpriteFont);

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

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

            controlButton.AnchorPoint = CCPoint.AnchorMiddleTop;
            controlButton.Position = screenSize.Center;
            AddChild(controlButton, 1);

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

            // Sets up event handlers
            controlButton.TouchDown += ControlButton_TouchDown;
            controlButton.TouchDragInside += ControlButton_TouchDragInside;
            controlButton.TouchDragOutside += ControlButton_TouchDragOutside;
            controlButton.TouchDragEnter += ControlButton_TouchDragEnter;
            controlButton.TouchDragExit += ControlButton_TouchDragExit;
            //controlButton.TouchUpInside += ControlButton_TouchUpInside;
            controlButton.TouchUpOutside += ControlButton_TouchUpOutside;
            controlButton.TouchCancel += ControlButton_TouchCancel;

            // To see clicked events your will need comment out TouchUpInside events
            controlButton.Clicked += ControlButton_Clicked;
        }
示例#3
0
        public CCControlButtonTest_Event()
		{
			CCSize screenSize = Layer.VisibleBoundsWorldspace.Size;

			// 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(CCColor3B.White, 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);
		}
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = Layer.VisibleBoundsWorldspace.Size;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);

            var statusLabel = new CCLabel("Scale9Enabled", "arial", 10, CCLabelFormat.SpriteFont);
            statusLabel.PositionX = x;
            statusLabel.PositionY = winSize.Height - statusLabel.ContentSize.Height - 100;
            AddChild(statusLabel);

            var normalSprite = CCScale9Sprite.SpriteWithFrameName("blocks9r.png");

            normalSprite.PositionX = x;
            normalSprite.PositionY = y;
            AddChild(normalSprite);


            var normalLabel = new CCLabel("Normal Sprite", "Arial", 10, CCLabelFormat.SpriteFont);
            normalLabel.Position += normalSprite.Position +
                new CCPoint(0, normalSprite.ScaledContentSize.Height / 2 + 10);
            AddChild(normalLabel);



            var flipXSprite = CCScale9Sprite.SpriteWithFrameName("blocks9r.png");

            flipXSprite.PositionX = x - 150;
            flipXSprite.PositionY = y;
            flipXSprite.Scale = 1.2f;
            AddChild(flipXSprite);
            flipXSprite.IsFlippedX = false;

            var flipXLabel = new CCLabel("sprite is not flipped!", "Arial", 10, CCLabelFormat.SpriteFont);
            flipXLabel.Position = flipXSprite.Position +
                new CCPoint(0, flipXSprite.ScaledContentSize.Height / 2 + 10);
            AddChild(flipXLabel);


            var flipYSprite = CCScale9Sprite.SpriteWithFrameName("blocks9r.png");

            flipYSprite.PositionX = x + 150;
            flipYSprite.PositionY = y;
            flipYSprite.Scale = 0.8f;
            AddChild(flipYSprite);
            flipYSprite.IsFlippedY = true;

            var flipYLabel = new CCLabel("sprite is flipped!", "Arial", 10, CCLabelFormat.SpriteFont);
            flipYLabel.Position = flipYSprite.Position + 
                new CCPoint(0, flipYSprite.ScaledContentSize.Height / 2 + 10);
            AddChild(flipYLabel);


            var toggleFlipXButton = new CCControlButton("Toggle FlipX", "arial", 12);
            
            toggleFlipXButton.Position = flipXSprite.Position +
                new CCPoint(0, -20 - flipXSprite.ScaledContentSize.Height / 2);


            toggleFlipXButton.Clicked += (obj, cevent) =>
            {
                flipXSprite.IsFlippedX = !flipXSprite.IsFlippedX;
                if (flipXSprite.IsFlippedX)
                    flipXLabel.Text = "sprite is flipped";
                else
                    flipXLabel.Text = "sprite is not flipped";
            };

            AddChild(toggleFlipXButton);

            var toggleFlipYButton = new CCControlButton("Toggle FlipY", "arial", 12);
            toggleFlipYButton.Position = flipYSprite.Position + 
                new CCPoint(0, -20 - flipYSprite.ScaledContentSize.Height / 2);

            toggleFlipYButton.Clicked += (obj, cevent) =>
            {
                flipYSprite.IsFlippedY = !flipYSprite.IsFlippedY;
                if (flipYSprite.IsFlippedY)
                    flipYLabel.Text = "sprite is flipped";
                else
                    flipYLabel.Text = "sprite is not flipped";
            };

            AddChild(toggleFlipYButton);

            var toggleScale9Button = new CCControlButton("Toggle Scale9", "arial", 12);
            toggleScale9Button.Position = normalSprite.Position + 
                new CCPoint(0, -20 - normalSprite.ContentSize.Height / 2);

            toggleScale9Button.Clicked += (obj, cevent) =>
            {
                flipXSprite.IsScale9Enabled = !flipXSprite.IsScale9Enabled;
                flipYSprite.IsScale9Enabled = !flipYSprite.IsScale9Enabled;

                if (flipXSprite.IsScale9Enabled)
                    statusLabel.Text = "Scale9Enabled";
                else
                    statusLabel.Text = "Scale9Disabled";

                if (flipXSprite.IsFlippedX)
                    flipXLabel.Text = "sprite is flipped";
                else
                    flipXLabel.Text = "sprite is not flipped";

                if (flipYSprite.IsFlippedY)
                    flipYLabel.Text = "sprite is flipped";
                else
                    flipYLabel.Text = "sprite is not flipped";
            };

            AddChild(toggleScale9Button);
        }