public override bool Init() { if (base.Init()) { CCSize screenSize = CCDirector.SharedDirector.WinSize; // Add a label in which the slider value will be displayed m_pDisplayValueLabel = new CCLabelTTF("Move the slider thumb!\nThe lower slider is restricted.", "Marker Felt", 32); m_pDisplayValueLabel.AnchorPoint = new CCPoint(0.5f, -1.0f); m_pDisplayValueLabel.Position = new CCPoint(screenSize.Width / 1.7f, screenSize.Height / 2.0f); AddChild(m_pDisplayValueLabel); // Add the slider var slider = new CCControlSlider("extensions/sliderTrack", "extensions/sliderProgress", "extensions/sliderThumb"); slider.AnchorPoint = new CCPoint(0.5f, 1.0f); slider.MinimumValue = 0.0f; // Sets the min value of range slider.MaximumValue = 5.0f; // Sets the max value of range slider.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f + 16); slider.Tag = 1; // When the value of the slider will change, the given selector will be call slider.AddTargetWithActionForControlEvents(this, valueChanged, CCControlEvent.ValueChanged); var restrictSlider = new CCControlSlider("extensions/sliderTrack", "extensions/sliderProgress", "extensions/sliderThumb"); restrictSlider.AnchorPoint = new CCPoint(0.5f, 1.0f); restrictSlider.MinimumValue = 0.0f; // Sets the min value of range restrictSlider.MaximumValue = 5.0f; // Sets the max value of range restrictSlider.MaximumAllowedValue = 4.0f; restrictSlider.MinimumAllowedValue = 1.5f; restrictSlider.Value = 3.0f; restrictSlider.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f - 24); restrictSlider.Tag = 2; //same with restricted restrictSlider.AddTargetWithActionForControlEvents(this, valueChanged, CCControlEvent.ValueChanged); AddChild(slider); AddChild(restrictSlider); return true; } return false; }
/** * Creates a slider with a given background sprite and a progress bar and a * thumb item. * * @see initWithBackgroundSprite:progressSprite:thumbMenuItem: */ public static CCControlSlider Create(CCSprite backgroundSprite, CCSprite pogressSprite, CCSprite thumbSprite) { var pRet = new CCControlSlider(); pRet.InitWithSprites(backgroundSprite, pogressSprite, thumbSprite); return pRet; }