Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Core.Button"/> class.
        /// </summary>
        /// <param name="father">Father node for the button.</param>
        /// <param name="tl">Touch listener.</param>
        /// <param name="method">Method to call when the button is pressed. Must be coherent with the delegate <see cref="Core.touchList.eventHandlerTouch"/>.</param>
        /// <param name="textureDefault">Texture for normal state.</param>
        /// <param name="texturePressed">Texture for pressed state.</param>
        /// <param name="position">Position of the button.</param>
        /// <param name="winSize">Window size.</param>
        /// <param name="rot">Rotation of the button.</param>
        /// <param name="scale">Scale of the button.</param>
        /// <param name="order">ZOrder (depth).</param>
        internal CCButton(CCNode father, TouchList tl, TouchList.eventHandlerTouch method, string textureDefault, string texturePressed, CCPoint position, CCSize winSize, float rot = -90, float scale = 0.55f, int order = 0)
        {
            //Defining the sprite
            _spriteNorm          = new CCSprite(textureDefault);
            _spriteNorm.Position = position;
            _spriteNorm.Rotation = rot;
            _spriteNorm.Scale    = scale;
            father.AddChild(_spriteNorm);

            _spritePressed          = new CCSprite(texturePressed);
            _spritePressed.Position = position;
            _spritePressed.Rotation = rot;
            _spritePressed.Scale    = scale;
            father.AddChild(_spritePressed);
            _spritePressed.Visible = false;

            this._winSize = winSize;
            this._father  = father;

            //Defining the event variables
            _onButtonPressed        = method;
            _pressed                = false;
            _touch                  = tl;
            _touch.eventTouchBegan += touchBegan;
            _touch.eventTouchEnded += touchEnded;
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Core.Slider"/> class.
        /// </summary>
        /// <param name="mainLayer">Main layer.</param>
        /// <param name="tl">Touch listener.</param>
        /// <param name="textureBar">Texture of the slider bar.</param>
        /// <param name="texturePoint">Texture of the slider point.</param>
        /// <param name="position">Position of the slider.</param>
        /// <param name="winSize">Window size.</param>
        /// <param name="min">Minimum value of the slider.</param>
        /// <param name="max">Maximum value of the slider.</param>
        /// <param name="rot">Rotation of the slider sprite (default -90).</param>
        /// <param name="scale">Scale of the slider sprite (default 0.8f).</param>
        internal CCSlider(CCLayer mainLayer, TouchList tl, string textureBar, string texturePoint, CCPoint position, CCSize winSize, int min, int max, float rot = -90, float scale = 0.8f)
        {
            //Defining the sprite
            spriteBar             = new CCSprite(textureBar);
            spriteBar.AnchorPoint = new CCPoint(0, 0.5f);
            spriteBar.Position    = position;
            spriteBar.Rotation    = rot;
            spriteBar.Scale       = scale;
            spriteBar.BlendFunc   = CCBlendFunc.AlphaBlend;
            mainLayer.AddChild(spriteBar);

            spritePoint = new CCSprite(texturePoint);
            spriteBar.AddChild(spritePoint);
            spritePoint.Position  = new CCPoint(0, spriteBar.ContentSize.Height / 2);
            spritePoint.Scale     = scale * 0.4f;
            spritePoint.BlendFunc = CCBlendFunc.AlphaBlend;

            _min = min;
            _max = max;

            _currentValue = _min;


            lblValue          = new CCLabel(_currentValue.ToString(), "Arial", 65 * scale);
            lblValue.Position = new CCPoint(spriteBar.ContentSize.Width / 2, -0.05f * spriteBar.ContentSize.Height);
            spriteBar.AddChild(lblValue);

            this.winSize   = winSize;
            this.mainLayer = mainLayer;



            this.scale = scale;

            //Defining the event variables
            touch = tl;
            touch.eventTouchBegan += touchBegan;
            touch.eventTouchMoved += touchMoved;
        }