1

我添加了逻辑来显示 Sprite 动画,但它根本没有显示在屏幕上。我究竟做错了什么?

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;

namespace MyXNAGame.Game_Classes
{
  public class Player : Sprite
  {
    private int _frameCount = 6;
    private int _frameIndex;
    private Rectangle[] _frames;
    public float _jumpVelocity = 12f;
    public PlayerState _playerState;

    public Rectangle BoundingBox
    {
        get { return new Rectangle {X = (int) Position.X, Y = (int) Position.Y, Height = Texture.Height, Width = Texture.Width}; }
    }

    public void Initialize()
    {
        _frames = new Rectangle[_frameCount];
        int width = Texture.Width / _frameCount;
        for (int i = 0; i < _frameCount; i++)
        {
            _frames[i] = new Rectangle(i*width, 0, width, Texture.Height);
        }
    }

    public void Load(ContentManager contentManager, string assetName)
    {
        Texture = contentManager.Load<Texture2D>(assetName);
    }

    public void Update(GameTime gameTime)
    {
        while (TouchPanel.IsGestureAvailable)
        {
            GestureSample gestureSample = TouchPanel.ReadGesture();
            if (gestureSample.GestureType == GestureType.Tap)
            {
                if (_playerState == PlayerState.Running)
                {
                    _playerState = PlayerState.NormalJump;
                }
            }
            if (gestureSample.GestureType == GestureType.Hold)
            {
                if (_playerState == PlayerState.Running)
                {
                    _playerState = PlayerState.LongJump;
                }
            }
        }

        // NormalJump Logic
        switch (_playerState)
        {
            case PlayerState.NormalJump:
                Position.Y -= _jumpVelocity;
                _jumpVelocity -= 0.5f;
                if (_jumpVelocity == 0)
                {
                    _playerState = PlayerState.Falling;
                }
                break;
            case PlayerState.LongJump:
                Position.Y -= _jumpVelocity;
                _jumpVelocity -= 0.5f;
                if (_jumpVelocity == 0)
                {
                    _playerState = PlayerState.Falling;
                }
                break;
            case PlayerState.Falling:
                Position.Y += _jumpVelocity;
                _jumpVelocity += 0.5f;
                break;
            case PlayerState.Running:
                _frameIndex++;
                if (_frameIndex > 5)
                {
                    _frameIndex = 0;
                }

                break;
        }
    }

    public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Draw(Texture, Position, _frames[_frameIndex], Color.White, 0, new Vector2(0, 0), new Vector2(0, 0), SpriteEffects.None, 0);
    }
}

}`

任何人都可以看到明显的错误吗?我正在使用 WP7

4

1 回答 1

1

我将 Draw() 方法中的“Scale”参数从 new Vector(0,0) 更改为 new Vector(1,1),显然,Scale 为 0 根本不会显示任何内容。

于 2013-03-24T02:44:26.240 回答