English 中文(简体)
XNA: 在一个数组中存储大量纹理2D
原标题:XNA: Storing lots of Texture2D in an array

I m starting out with xna, I m pretty newbie with this, but I m making my efforts to go on with this framework, anymay, my problem is: that I have many .png images and dont want to make an object for any of those images so I want to put them up in a Texture2D array, I thought that this is way to do it, but looks like it s not the correct way:

Texture2D[] _rCards, _bCards, _sCards;
_bCards = new Texture2D[9]; 
_rCards = new Texture2D[9];
_sCards = new Texture2D[6];

for (int i = 1; i < 10; i++)
{
    _bCards[i] = Content.Load<Texture2D>("Images/Common/Black/"+i);
    _rCards[i] = Content.Load<Texture2D>("Images/Common/Red/"+i);
    if(i<6)
        _sCards[i] = Content.Load<Texture2D>("Images/Special/Card" + (i-1));
}

纹理的文件名称为 1.png、 2.png、 3.png等等。

特殊卡片是卡片1png、卡片2png、卡片3png等。

我想做个21点的游戏

你能给我一个建议吗? 把所有这些纹理 装入一个单一的纹理2D阵列。

IDE 给出了一个无止境的专利问题 或什么的。

也许语言不理解 整个缩写 找到纹理作为字符串。

最佳回答

指数以 0 为基础...

for (int i = 1; i < 10; i++)
{
  _bCards[i-1] = Content.Load("Images/Common/Black/"+i);
  _rCards[i-1] = Content.Load("Images/Common/Red/"+i);
   if(i<6) _sCards[i-1] = Content.Load("Images/Special/Card" + (i-1));
}

如果您想要同时装入所有纹理, 您可以使用图例工作表样本 :

http://create.msdn.com/en-US/education/catalog/sample/sprite_sheech" rel=“nofollow>http://create.msdn.com/en-US/education/catalog/sample/sprite_shite

您将有独特的资产和源矩形字典来绘制图示...

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签