-1

私は C# の完全な初心者です (昨日学習を始めたばかりです)。このリンクのチュートリアルに従っています: http://msdn.microsoft.com/en-us/library/bb203893.aspx。私が抱えている問題は、スプライトを1ピクセルも動かせないように見えることです。(私はすでに主題を読んでいて、実際には役に立たなかったいくつかのことを追加してしまいました)。これが私が立ち往生しているコードです:

 void UpdateSprite(GameTime gameTime)
    {
        {
            Update(gameTime);
        }

        spritePosition +=
            spritePosition * (float)gameTime.ElapsedGameTime.TotalSeconds;

        int MaxX =
            graphics.GraphicsDevice.Viewport.Width - myTexture.Width;
        int MinX = 0;
        int MaxY =
            graphics.GraphicsDevice.Viewport.Height - myTexture.Height;
        int MinY = 0;


        if (spritePosition.X > MaxX)
        {
            spriteSpeed.X *= -1;
            spritePosition.X = MaxX;
        }

        else if (spritePosition.X < MinX)
        {
            spriteSpeed.X *= -1;
            spritePosition.X = MinX;
        }

        if (spritePosition.Y > MaxY)
        {
            spriteSpeed.Y *= -1;
            spritePosition.Y = MaxY;
        }

        else if (spritePosition.Y < MinY)
        {
            spriteSpeed.Y *= -1;
            spritePosition.Y = MinY;
        }


        // 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);


        spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
        spriteBatch.Draw(myTexture, spritePosition, Color.White);
        spriteBatch.End();

        // TODO: Add your drawing code here

        base.Draw(gameTime);
    }
}

}

4

1 に答える 1

1

このステートメントは、次のことを行う必要があります。

spritePosition += spritePosition * (float)gameTime.ElapsedGameTime.TotalSeconds;

代わりに次のように読む必要があります。

spritePosition += spriteSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
于 2013-02-13T12:49:07.793 に答える