public override void OnEnter() { base.OnEnter(); CCSize screenSize = Layer.VisibleBoundsWorldspace.Size; // 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 int i = 0; foreach(var title in stringArray) { // Creates a button with this string as title var button = standardButtonWithTitle(title); if (i == 0) { button.Opacity = 50; button.Color = new CCColor3B(0, 255, 0); } else if (i == 1) { button.Opacity = 200; button.Color = new CCColor3B(0, 255, 0); } else if (i == 2) { button.Opacity = 100; button.Color = new CCColor3B(0, 0, 255); } 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; i++; } 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); }
public override void OnEnter() { base.OnEnter(); var screenSize = Layer.VisibleBoundsWorldspace.Size; var layer = new CCNode (); layer.Position = screenSize.Center; AddChild(layer, 1); var layerWidth = 0.0f; // Add the black background for the text var background = new CCScale9SpriteFile("extensions/buttonBackground"); background.ContentSize = new CCSize(80, 50); background.Position = new CCPoint(layerWidth + background.ContentSize.Width / 2.0f, 0); layer.AddChild(background); layerWidth += background.ContentSize.Width; DisplayValueLabel = new CCLabel("#color", "Arial", 30, CCLabelFormat.SpriteFont); DisplayValueLabel.Position = background.Position; layer.AddChild(DisplayValueLabel); // 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 CCLabel("On", "Arial", 16, CCLabelFormat.SpriteFont), new CCLabel("Off", "Arial", 16, CCLabelFormat.SpriteFont) ); switchControl.Position = new CCPoint(layerWidth + 10 + switchControl.ContentSize.Width / 2, 0); layer.AddChild(switchControl); // Subscribe to the switches StateChanged event switchControl.StateChanged += SwitchControl_StateChanged; // --------------- OR --------------------- // we can subscribe to the ValueChanged event. //switchControl.ValueChanged += SwitchControl_ValueChanged; // Set the layer size layer.ContentSize = new CCSize(layerWidth, 0); layer.AnchorPoint = CCPoint.AnchorMiddle; // Update the value label ValueChanged(switchControl, CCControlEvent.ValueChanged); }
/** 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 CCControlScene() { // Get the screensize CCSize screensize = Layer.VisibleBoundsWorldspace.Size; 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); }
public override void OnEnter() { base.OnEnter(); var screenSize = Layer.VisibleBoundsWorldspace.Size; var layer = new CCNode(); layer.Position = screenSize.Center; 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 CCLabel("", "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.ValueChanged += Potentiometer_ValueChanged; layer.AddChild(potentiometer); layer_width += potentiometer.ContentSize.Width; // Set the layer size layer.ContentSize = new CCSize((float) layer_width, 0); layer.AnchorPoint = CCPoint.AnchorMiddle; // Update the value label ValueChanged(potentiometer, CCControlEvent.ValueChanged); }
public CCControlColourPickerTest() { CCSize screenSize = Layer.VisibleBoundsWorldspace.Size; 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); }
public CCControlSwitchTest() { CCSize screenSize = Layer.VisibleBoundsWorldspace.Size; 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); }
public CCControlPotentiometerTest() { CCSize screenSize = Layer.VisibleBoundsWorldspace.Size; 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); }
public override void OnEnter() { base.OnEnter(); CCSize screenSize = Layer.VisibleBoundsWorldspace.Size; 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 CCLabel("0", "Arial", 26, CCLabelFormat.SpriteFont); 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.ValueChanged += Stepper_ValueChanged; layer.AddChild(stepper); layer_width += stepper.ContentSize.Width; // Set the layer size layer.ContentSize = new CCSize(layer_width, 0); layer.AnchorPoint = CCPoint.AnchorMiddle; // Update the value label ValueChanged(stepper, CCControlEvent.ValueChanged); }
public CCControlStepperTest() { CCSize screenSize = Layer.VisibleBoundsWorldspace.Size; 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); }
public CCControlButtonTest_Styling() { CCSize screenSize = Layer.VisibleBoundsWorldspace.Size; 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); }
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 CCControlButtonTest_Inset() { 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; // 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); }
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 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); }