【发布时间】:2015-04-08 02:15:00
【问题描述】:
第一篇文章,一年级程序员,请放轻松。
在单人游戏中绘制精灵时,有人知道如何将其拉伸到全屏吗?
例如,我的开始屏幕出现了,但它没有延伸到全屏(因为我的窗口在打开时最大化)。我有“spriteBatch.Draw(startScreen, Vector2.Zero, null, Color.White);”
null 表示矩形属性。有没有人知道一个词来替换 null 以便拉伸它?
这是我的纹理加载内容:
startScreen = Content.Load<Texture2D>("Images/startGameSplash");
这就是我在 Draw Method 中调用它的地方:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
switch (gameState)
{
case GameState.StartScreen:
//draw the start screen
spriteBatch.Begin();
spriteBatch.Draw(startScreen, Vector2.Zero, null, Color.White);
//Drawing each rocket with another foreach
spriteBatch.End();
break;
case GameState.Running:
spriteBatch.Begin();
tank.Draw(spriteBatch);
foreach (BaseRocket shot in rocket) {
shot.Draw(spriteBatch);
}
spriteBatch.End();
break;
case GameState.EndScreen:
spriteBatch.Begin();
spriteBatch.Draw(endScreen, Vector2.Zero, null, Color.White);
spriteBatch.End();
break;
default:
break;
}
base.Draw(gameTime);
}
}
}
谢谢,
【问题讨论】:
-
你能显示更多代码吗?
-
完成了,还需要更多吗?
-
暂时还好。如果你阅读了
SpriteBatch类的monogame 的文档/source code,你会看到:public void Draw (Texture2D texture, Rectangle rectangle, Color color),其中第二个参数是精灵的大小。将屏幕大小矩形分配给参数,您的精灵应该填满屏幕。 -
得到它的工作谢谢。我用 spriteBatch.Draw(startScreen, new Rectangle(0,0,GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
-
很高兴知道代码现在正在运行。我将评论格式化为下面的答案。如果觉得有用请采纳,谢谢。