XNA 3.1 迟缓运动
我有Windows XP SP3。
我在版本 3.1 中创建了默认的 XNA 项目,并将这些简单的行添加到预生成的代码中:
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Rectangle rectangle = new Rectangle(80, 80, 100, 100);
Texture2D textureTrain;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 10);
}
...
/// <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.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
textureTrain = Content.Load<Texture2D>("MyBitmap1");
}
...
/// <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
rectangle.X = rectangle.X + 1;
rectangle.Y = rectangle.Y + 1;
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
spriteBatch.Begin();
spriteBatch.Draw(textureTrain, rectangle, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
就这么简单!但动作非常迟缓,闪烁,我什至无法直视。 如果我把它与一些Flash游戏相比,那是无可比拟的。这是为什么呢?我做错了什么?
I have Windows XP SP3.
I created the default XNA project in version 3.1 and added these simple lines to the pregenerated code:
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Rectangle rectangle = new Rectangle(80, 80, 100, 100);
Texture2D textureTrain;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
//TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 10);
}
...
/// <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.
spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
textureTrain = Content.Load<Texture2D>("MyBitmap1");
}
...
/// <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
rectangle.X = rectangle.X + 1;
rectangle.Y = rectangle.Y + 1;
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
spriteBatch.Begin();
spriteBatch.Draw(textureTrain, rectangle, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
as simple as this ! But the movement is very laggy, it flickers, I can't even look at it.
If I compare it to some flash games it's incomparable. Why is this? What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您使用的是矩形的 X 和 Y 分量,因此您的计算将四舍五入到最接近的整数。在这种情况下,您需要粒度,即精细、精确的运动。
IE
Because your are using the X and Y components of the Rectangle, your calculation will be rounded to the nearest whole number. You want granularity in this case, fine, precise movements.
i.e.