มาปูหญ้ากัน (tile 2D)

posted on 13 Jan 2008 21:21 by xnanoob  in Tutorials

สวัสดีค่า

วันนี้หัดปูหญ้ากันนะค่ะ (ตัวอย่างนี้เป็นตัวอย่างแรกๆ เลยในหนังสือ 360)

หลักการคือ จะการวาด texture ซ้ำๆ กันไปให้เต็มจอนะ โดยหาขนาดความกว้างและความสูงของหน้าจอที่แสดงผล


หา texture ที่จะใช้มา

ผลการทดลอง




แต่ไม่รู้เหมือนกันว่าถ้าจะทำแบบกระเบื้องลีลา ?? ไม่รู้จะทำยังไง ถ้า Texture ไม่สี่เหลี่ยม จะปูไงดี?
เฮือก ... ใครรู้บอกหน่อยเด้อ

 

#region Draw Tile

int resolutionWidth = ScreenManager.GraphicsDevice.Viewport.Width;

int resolutionHeight = ScreenManager.GraphicsDevice.Viewport.Height;

for (int x = 0; x <= resolutionWidth / backgroundTexture.Width; x++)for (int y = -1; y <= resolutionHeight / backgroundTexture.Height; y++)

{

Vector2 position = new Vector2(

x * backgroundTexture.Width,

y * backgroundTexture.Height + ((int)scrollPosition) % backgroundTexture.Height);spriteBatch.Draw(backgroundTexture, position,

Color.White);

} // for for

#endregion

จบแระค่ะ บายค่ะ
งุงิงุงิ

อบรม เรียน สอน PHP+MySQL
อบรม เรียน สอน PHP+MySQL พัฒนาเว็บไซด์

Comment



smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry