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