我在 C# 中使用 XNA 绘制图形
View = Matrix.CreateLookAt(new Vector3(0f, 100f, 0f), Vector3.Zero, Vector3.Forward);
Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(20.0f), ((Game1)Game).graphics.GraphicsDevice.Viewport.AspectRatio, 1.0f, 10000.0f);
我的相机从不移动,只有我的游戏对象移动。我以下列方式移动它们以获得平滑的运动
float speed = 0.001f;
pos.Z = pos.Z + (gameTime.ElapsedGameTime.Milliseconds * speed);
但是,我有道路瓷砖(Primitives VertexPositionTexture)要在另一个之后渲染,以给人一种道路行驶的感觉。
它有效,但有时它是我不想要的道路瓷砖之间的像素间距。我认为这与浮点坐标有关。
我应该如何解决这个问题?
提前致谢!我希望我的解释清楚我的问题。
编辑1:如果有人想对这篇文章投反对票,请评论原因。没有反馈就很难开发。
编辑 2:关于原语的信息。
杆 1 上的 res 400 x 50
using System;
using System.Collections.Generic;
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.Media;
namespace WindowsGame1
{
class Rod
{
public static Microsoft.Xna.Framework.Graphics.VertexBuffer buffer;
public static Texture2D[] tex;
public static BasicEffect effect;
public Vector3 pos;
public int typ;
public const float Width = 24f;
public const float Height = 5;
public Rod(Vector3 pos,Random r)
{
this.pos = pos;
typ = r.Next(tex.Length);
}
static public void Initialize(GraphicsDevice g)
{
buffer = new VertexBuffer(g, VertexPositionTexture.VertexDeclaration, 6, BufferUsage.WriteOnly);
VertexPositionTexture[] vertices = new VertexPositionTexture[6];
vertices[0].Position = new Vector3(-Width, 0f, -Height);
vertices[0].TextureCoordinate.X = 0;
vertices[0].TextureCoordinate.Y = 0;
vertices[1].Position = new Vector3(Width, 0f, Height);
vertices[1].TextureCoordinate.X = 1;
vertices[1].TextureCoordinate.Y = 1;
vertices[2].Position = new Vector3(-Width, 0f, Height);
vertices[2].TextureCoordinate.X = 0;
vertices[2].TextureCoordinate.Y = 1;
vertices[3].Position = new Vector3(Width, 0f, Height);
vertices[3].TextureCoordinate.X = 1;
vertices[3].TextureCoordinate.Y = 1;
vertices[4].Position = new Vector3(-Width, 0f, -Height);
vertices[4].TextureCoordinate.X = 0;
vertices[4].TextureCoordinate.Y = 0;
vertices[5].Position = new Vector3(Width, 0f, -Height);
vertices[5].TextureCoordinate.X = 1;
vertices[5].TextureCoordinate.Y = 0;
buffer.SetData<VertexPositionTexture>(vertices);
effect = new BasicEffect(g);
effect.TextureEnabled = true;
}
public void SetTyp(Random r)
{
typ = r.Next(tex.Length);
}
public void Update(GameTime gameTime, Double speed)
{
// pos = new Vector3(pos.X, pos.Y, pos.Z + (gameTime.ElapsedGameTime.Milliseconds * speed) );
pos.Z = pos.Z + (float)(gameTime.ElapsedGameTime.Milliseconds * speed);
}
public void Draw(Matrix View, Matrix Projection, GraphicsDevice g)
{
effect.World = Matrix.CreateScale(1.01f) * Matrix.CreateTranslation(pos);
effect.View = View;
effect.Projection = Projection;
effect.Texture = tex[typ];
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
g.SetVertexBuffer(buffer);
pass.Apply();
g.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
}
}
}
}