void LoadMenu() { var bounds = mainLayer.VisibleBoundsWorldspace; var center = bounds.Center; var startGameButton = new CCScale9Sprite("redButton"); startGameButton.AnchorPoint = CCPoint.AnchorMiddle; startGameButton.CapInsets = new CCRect(20, 20, 42, 42); startGameButton.ContentSize = new CCSize((mWidth * 0.4f), (mHeight * 0.2f)); var startGameLabel = new CCLabel("Load Icon Board", "Fonts/MarkerFelt", 22, CCLabelFormat.SpriteFont); buttonControl = new CCControlButton(startGameLabel, startGameButton); var scale = (mWidth * 0.4f) / buttonControl.ContentSize.Width; startGameLabel.Scale = scale; buttonControl.PreferredSize = new CCSize(startGameButton.ContentSize.Width * scale, startGameButton.ContentSize.Height * scale); buttonControl.PositionX = center.X; buttonControl.PositionY = bounds.Size.Height / 4.0f; buttonControl.Clicked += PressedButton; mainLayer.AddChild(buttonControl); }
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; }
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); }
/** 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; // 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; var insetRect = new CCRect(5, 5, 5, 5); // For each title in the array foreach (var title in stringArray) { // Creates a button with this string as title CCControlButton button = insetButtonWithTitle(title, insetRect); 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 = CCPoint.AnchorMiddle; layer.ContentSize = new CCSize(total_width, height); layer.Position = screenSize.Center; // Add the black background var background = new CCScale9SpriteFile("extensions/buttonBackground"); background.ContentSize = new CCSize(total_width + 14, height + 14); background.Position = screenSize.Center; AddChild(background); }
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); }
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); }
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); }
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); }