【发布时间】:2015-05-09 20:28:33
【问题描述】:
我正在尝试以某种方式将纹理平铺到矩形。例如,这是我的纹理:
目前,它将它平铺到我的矩形上,这样纹理在矩形顶部被切断:
我想平铺我的纹理,使其在矩形底部被切断:
我使用以下逻辑在我的游戏中创建和绘制一个矩形并将其平铺:
public class HoopsGame : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Body _ground;
Texture2D _groundTexture;
World _world;
public HoopsGame()
{
graphics = new GraphicsDeviceManager(this);
}
protected override void Initialize()
{
Content.RootDirectory = "Content";
_world = new World(new Vector2(0f, 9.8f));
int groundHeight = (int)(graphics.GraphicsDevice.Viewport.Height * 0.05);
Rectangle groundRectangle = new Rectangle(0, graphics.GraphicsDevice.Viewport.Height - groundHeight, graphics.GraphicsDevice.Viewport.Width, groundHeight);
_ground = BodyFactory.CreateRectangle(_world, groundRectangle.Width, groundRectangle.Height, 0f, groundRectangle);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
_groundTexture = Content.Load<Texture2D>("court");
}
protected override void UnloadContent()
{
Content.Unload();
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.White);
spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Opaque, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone);
spriteBatch.Draw(_groundTexture, new Vector2(0, graphics.GraphicsDevice.Viewport.Height - ((Rectangle)_ground.UserData).Height), (Rectangle)_ground.UserData, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
【问题讨论】:
标签: c# .net xna textures farseer