精灵在Windows Phone游戏中无法正确绘制(SDK 7.1)

时间:2012-07-03 04:18:07

标签: windows-phone-7 xna sprite

由于我安装了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);
    }
}
}

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

'Windows Phone 7 XNA游戏教程第2部分 - 绘图&amp;物理学第1部分 - MangoLander' 在名为'TradeMarkNZ'的频道上(对不起,因为我是新手我不能发布更多2个链接)

---------------- UPDATE --------------

我不确定这是解决这个问题的正确答案,但我刚刚通过添加这一行解决了这个问题:

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

0 个答案:

没有答案