0

由于我安装了 SDK 7.1,我在绘制精灵时遇到了问题,我的精灵就像被切割成一堆条纹,然后以一种奇怪的方式绘制。有人知道这里发生了什么吗?

这是我要绘制的精灵:

http://tinypic.com/r/sdeiop/6

这是我在运行应用程序时在模拟器屏幕上看到的内容

(也在 tinypic 中)/r/4ij4o0/6

这是我所有的代码

Game1.cs 类:

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace Ships
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    // Nave = Ship, jugador = player (in spanish)
    private Nave jugador;

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";

        // Frame rate is 30 fps by default for Windows Phone.
        TargetElapsedTime = TimeSpan.FromTicks(333333);

        // Extend battery life under lock.
        InactiveSleepTime = TimeSpan.FromSeconds(1);
    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here

        this.jugador = new Nave();

        base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        this.spriteBatch = new SpriteBatch(GraphicsDevice);

        this.jugador.LoadContent(this.Content, "Texturas\\nave");
        this.jugador.posicion.X = this.graphics.GraphicsDevice.Viewport.Width / 2 - jugador.textura.Width / 2;
        this.jugador.posicion.Y = this.graphics.GraphicsDevice.Viewport.Height - jugador.textura.Height;

        // TODO: use this.Content to load your game content here
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// all content.
    /// </summary>
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            this.Exit();

        // TODO: Add your update logic here

        base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        // TODO: Add your drawing code here
        this.spriteBatch.Begin();
        this.jugador.Draw(this.spriteBatch);
        this.spriteBatch.End();

        base.Draw(gameTime);
    }
}
}

这是我的船级(Nave.cs)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Ships
{
class Nave
{
    public Vector2 posicion = new Vector2(0, 0);
    public Texture2D textura;
    public Rectangle rectangulo;

    public Nave()
    {
        rectangulo = new Rectangle();
    }

    public void LoadContent(ContentManager theContentManager, string theAssetName)
    {
        textura = theContentManager.Load<Texture2D>(theAssetName);
    }

    public void Draw(SpriteBatch theSpriteBatch)
    {
        //theSpriteBatch.Draw(textura, posicion, Color.White);
        rectangulo.X = (int)this.posicion.X;
        rectangulo.Y = (int)this.posicion.Y;
        rectangulo.Width = this.textura.Width;
        rectangulo.Height = this.textura.Height;

        theSpriteBatch.Draw(textura, posicion, null, Color.White, 0f, new Vector2(0, 0), 1, SpriteEffects.None, 0);
    }
}
}

在尝试运行本教程中的代码时,我首先注意到了这个问题

名为“TradeMarkNZ”的频道上的“Windows Phone 7 XNA 游戏教程第 2 集 - 绘图和物理第 1 部分 - MangoLander”(对不起,因为我是新手,所以不能发布超过 2 个链接)

- - - - - - - - 更新 - - - - - - -

我不确定这是这个问题的正确答案,但我只是通过添加以下行来解决它:

graphics.IsFullScreen = true;

到 Game1 类

工作构造函数:

public Game1()
{
    graphics = new GraphicsDeviceManager(this);
    graphics.IsFullScreen = true;
    Content.RootDirectory = "Content";

    // Frame rate is 30 fps by default for Windows Phone.
    TargetElapsedTime = TimeSpan.FromTicks(333333);

    // Extend battery life under lock.
    InactiveSleepTime = TimeSpan.FromSeconds(1);
}

在这里找到了答案:

http://forums.create.msdn.com/forums/p/102530/627643.aspx#627643

4

0 回答 0