如何设置此瓷砖使其成为一个地板?
我需要这个瓷砖纹理遍布整个屏幕宽度吗?
我怎么做的?
谢谢解决方法 如果你想要一个非常简单的方法,这里是:
首先,您创建一个新类并将其命名为Tile:
using System;using System.Collections.Generic;using System.linq;using System.Text;using Microsoft.Xna.Framework; // Don't forget those,they will let youusing Microsoft.Xna.Framework.Content; // access some class like:using Microsoft.Xna.Framework.Graphics; // Texture2D or Vector2namespace 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,但这是一个简单的方法:
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说的方式,代码可能更复杂,但这是你会理解的,我会添加一个SpriteBatch,所以我可以绘制.所有这些都是在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) } }
我没试过但它应该可以工作,现在它只是一个样本,你可以弄清楚剩下的.还有很多其他方法可以做到,但这个方法非常简单.好的,现在最后一步是实现这个类,所以进入你的主要类,你有你所有的代码,在此之前:
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# – 绘制“地板”纹理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)