Пример #1
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            animTimeElapsed += gameTime.ElapsedGameTime.TotalSeconds;
            if (animTimeElapsed >= animDelay)
            {
                animTimeElapsed = 0;

                if (currentAnim == ShipAnim.FlyLeft)
                {
                    --currentFrame;
                    if (currentFrame < FlyingAnimFrame.FarLeft)
                    {
                        currentFrame = FlyingAnimFrame.FarLeft;
                    }
                }
                else if (currentAnim == ShipAnim.FlyRight)
                {
                    ++currentFrame;
                    if (currentFrame > FlyingAnimFrame.FarRight)
                    {
                        currentFrame = FlyingAnimFrame.FarRight;
                    }
                }
                else
                {
                    // if we're not moving left or right, tilt back towards the center:
                    if (currentFrame > FlyingAnimFrame.Straight)
                    {
                        --currentFrame;
                    }
                    else if (currentFrame < FlyingAnimFrame.Straight)
                    {
                        ++currentFrame;
                    }
                }
            }

            sprite.UpdateRect(animFly[(int)currentFrame]);
            sprite.Draw(spriteBatch, new Vector2(xPos, yPos), SpriteEffects.None);
        }
Пример #2
0
        public override void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            animTimeElapsed += gameTime.ElapsedGameTime.TotalSeconds;
            if (animTimeElapsed >= animDelay)
            {
                animTimeElapsed = 0;

                if (currentAnim == ShipAnim.FlyLeft)
                {
                    --currentFrame;
                    if (currentFrame < FlyingAnimFrame.FarLeft) currentFrame = FlyingAnimFrame.FarLeft;
                }
                else if (currentAnim == ShipAnim.FlyRight)
                {
                    ++currentFrame;
                    if (currentFrame > FlyingAnimFrame.FarRight) currentFrame = FlyingAnimFrame.FarRight;
                }
                else
                {
                    // if we're not moving left or right, tilt back towards the center:
                    if (currentFrame > FlyingAnimFrame.Straight) --currentFrame;
                    else if (currentFrame < FlyingAnimFrame.Straight) ++currentFrame;
                }

            }

            sprite.UpdateRect(animFly[(int)currentFrame]);
            sprite.Draw(spriteBatch, new Vector2(xPos, yPos), SpriteEffects.None);
        }