我对此完全陌生,有一个问题。我在学校和家里做了一个练习,但我不知道该怎么做。
问题是我想在屏幕上的 10 个随机位置绘制单个精灵,而不使用特殊的精灵类。我的问题是,它们被绘制后又消失了。
解决了,谢谢大家的帮助!
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D turtleTexture;
int counter = 0;
Random randomera = new Random();
int x;
int y;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
/// <summary>
/// </summary>
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
turtleTexture = Content.Load<Texture2D>(@"Images/turtle_50x38");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
/*
if(counter < 10)
{
x = randomera.Next(600);
y = randomera.Next(400);
counter++;
}
*/
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
if (counter < 10)
{
for (int i = 0; i < 10; i++)
{
spriteBatch.Draw(turtleTexture, new Vector2(randomera.Next(600), randomera.Next(400)),
Color.Black);
counter++;
}
}
spriteBatch.End();
base.Draw(gameTime);
}
}
}