我想要程序做的是在.txt文件中出现的每个点绘制图形地面,但是每次我运行它时,它都不会绘制精灵?
这是代码......
using (StreamReader sr = new StreamReader("trainingLevel.txt"))
{
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
string[] elements = line.Split(',');
foreach (string e in elements)
{
int id = int.Parse(e);
if (id == 1)
{
CreatePlatform(x, y);
}
x += widthPlatform;
}
y += heightPlatform;
x = 0;
}
}
public void CreatePlatform(int x, int y)
{
groundSprite = new Sprite();
groundSprite.Position = new Vector2(x, y);
groundSprite.Load("Ground", Content, simulator);
groundSprite.IsStatic = true;
groundSprite.Geom.OnCollision += OnCollision;
}
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
List<Sprite> updateDraw = new List<Sprite>();
foreach (Sprite z in updateDraw) {
simulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);
z.Update(gameTime);
spriteBatch.Draw(z.CurrentTexture, z.Position, null, Color.White, z.Rotation, z.Origin, 1, SpriteEffects.None, 1);
}
spriteBatch.End();
base.Update(gameTime);
base.Draw(gameTime);
}