【发布时间】:2012-05-31 03:41:42
【问题描述】:
我目前为我正在编写的游戏加载了一个小行星纹理作为我的“测试玩家”。我试图弄清楚如何做的是从小行星的中心拍摄一个三角形,然后继续前进,直到它到达屏幕的顶部。在我的情况下会发生什么(正如您从我发布的代码中看到的那样),三角形会显示出来,但是它要么是一条长线,要么只是一个位于同一位置的三角形当小行星四处移动时(当我停止按空格键时它会消失),或者它根本不会出现。我尝试了许多不同的方法,但我可以在这里使用一个公式。
我要做的只是用 C# 为我的期末考试写一个太空侵略者克隆。我知道如何编码相当好,我的公式只需要工作就可以了。
到目前为止,这就是我所拥有的:
主逻辑代码
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 1, 1);
mAsteroid.Draw(mSpriteBatch);
if (mIsFired)
{
mPositions.Add(mAsteroid.LastPosition);
mRay.Fire(mPositions);
mIsFired = false;
mRay.Bullets.Clear();
mPositions.Clear();
}
base.Draw(gameTime);
}
绘制代码
public void Draw()
{
VertexPositionColor[] vertices = new VertexPositionColor[3];
int stopDrawing = mGraphicsDevice.Viewport.Width / mGraphicsDevice.Viewport.Height;
for (int i = 0; i < mRayPos.Length(); ++i)
{
vertices[0].Position = new Vector3(mRayPos.X, mRayPos.Y + 5f, 10);
vertices[0].Color = Color.Blue;
vertices[1].Position = new Vector3(mRayPos.X - 5f, mRayPos.Y - 5f, 10);
vertices[1].Color = Color.White;
vertices[2].Position = new Vector3(mRayPos.X + 5f, mRayPos.Y - 5f, 10);
vertices[2].Color = Color.Red;
mShader.CurrentTechnique.Passes[0].Apply();
mGraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, vertices, 0, 1);
mRayPos += new Vector2(0, 1f);
mGraphicsDevice.ReferenceStencil = 1;
}
}
【问题讨论】:
-
你能把它简化成一个简单的例子吗?所以我们可以在我们的电脑上重现它(+1 只是为了问题标题......哈哈)
-
我打开这个只是为了标题,好一个 :) 不过,你可能想改变它,以吸引那些可能真正帮助你解决问题的人