大佬教程收集整理的这篇文章主要介绍了c# – 绘制“地板”纹理,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; // Don't forget those,they will let you using Microsoft.Xna.Framework.Content; // access some class like: using Microsoft.Xna.Framework.Graphics; // Texture2D or Vector2 namespace Your_Project _Name { class Tile { } {
到目前为止一直很好,现在在你的类中创建纹理和位置,如下所示:
namespace Your_Project _Name { class Tile { Texture2D texture; Vector2 position; public void Initialize() { } public void Draw() { } } {
如你所见,我还创建了两个方法,Initialize和Draw,现在我们将初始化我们的
公共void Initialize()中的tile纹理的纹理和位置,
我不知道你如何使用你的ContentManager,但这是@L_197_1@简单的方法:
public void Initialize(ContentManager Content) { texture = Content.Load<Texture2D>("YourfloorTexture"); //it will load your texture. position = new Vector2(); //the position will be (0,0) }
现在我们需要多次绘制纹理,我们将如何做到这一点? thasc说的方式,代码可能更复杂,但这是你会理解的,我会添加@L_197_1@SpriteBatch,@R_401_9447@绘制.所有这些都是在public void Draw()中完成的:
public void Draw(SpriteBatch spriteBatch) { for (int i=0; i<30;i++) //will do a loop 30 times. Each Time i will = //a valor from 0 to 30. { spriteBatch.Draw(texture,position,Color.WhitE); //Will draw the texture once,at the position Vector2 //right Now position = (0,0) spriteBatch.Draw(texture,new Vector2((int)i,(int)i),Color.WhitE); //Will Draw the texture 30 times,the first time on the position (0,0) //Second Time on (1,1) .. third (2,2) etc... spriteBatch.Draw(texture,new Vector2((int)position.X + (i * texture.Width),(int)position.Y + (i * texture.Height),Color.WhitE)); //Will Draw the Texture 30 times Spaced by the Width and height //of the texture (this is the code you need) } }
我没试过但它应该可以工作,现在它只是@L_197_1@样本,你可以弄清楚剩下的.还有很多其他方法可以做到,但这个方法非常简单.好的,现在最后一步是实现这个类,所以进入你的主要类,你有你所有的代码,在此之前:
public Game1()
创建tile类的新实例
Tile tile;
并在受保护的覆盖中初始化void Initialize():
tile = new Tile(); tile.Initialize(Content);
现在你必须在屏幕上绘制它,在类的末尾找到protected override void Draw(GameTime gameTimE)并调用我们类的draw方法:
spriteBatch.begin(); tile.Draw(spriteBatch); spriteBatch.End();
以上是大佬教程为你收集整理的c# – 绘制“地板”纹理全部内容,希望文章能够帮你解决c# – 绘制“地板”纹理所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。