SpriteSheet.Update C# (CSharp) Method

Update() public method

public Update ( ) : void
return void
    void Update()
    {
        // Calculate index
        int index = (int)((Time.time - animationStart) * _fps) % (_uvTieX * _uvTieY);
        if( index > _lastIndex || (loop && index != _lastIndex))
        {
            // split into horizontal and vertical index
            int uIndex = index % _uvTieX;
            int vIndex = index / _uvTieY;

            // build offset
            // v coordinate is the bottom of the image in opengl so we need to invert.
            Vector2 offset = new Vector2 (uIndex * _size.x, 1.0f - _size.y - vIndex * _size.y);

            _myRenderer.material.SetTextureOffset ("_MainTex", offset);
            _myRenderer.material.SetTextureScale ("_MainTex", _size);

            _lastIndex = index;
        }
    }

Usage Example

Ejemplo n.º 1
0
        public void Update(GameTime gameTime, KeyboardState keyboard, object none)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
            float moveSpeed   = (float)moveAmount * elapsedTime;

            drawTranslation = drawPosition - position;
            if (RightDown(keyboard))
            {
                rotation += rotationSpeed;
            }
            else if (LeftDown(keyboard))
            {
                rotation -= rotationSpeed;
            }
            UpdateDirection(Rotation, RotationOffset, keyboard);
            velocity += acceleration * direction * elapsedTime;
            if (velocity.LengthSquared() > maxSpeed * maxSpeed)
            {
                velocity.Normalize();
                velocity *= maxSpeed;
            }
            position += velocity;
            for (int i = 0; i < anchorPoints.Count; i++)
            {
                //anchorPoints[i] += velocity;
            }
            velocity  *= friction;
            destRect.X = (int)position.X;
            destRect.Y = (int)position.Y;
            engineAnimation.Update(gameTime, keyboard, this);
        }
All Usage Examples Of SpriteSheet::Update