[英]Copying array of sprites in Visual C# and XNA
I am developing a Uno card game using Visual C# 2010 and XNA 4.0. 我正在使用Visual C#2010和XNA 4.0开发Uno纸牌游戏。 I have created an array of 108 element of all the Uno Cards as the array elements. 我创建了所有Uno卡的108个元素的数组作为数组元素。
Now I want to assign random 7 cards to each of the 4 players at the begining of the game. 现在,我想在游戏开始时向4个玩家中的每一个随机分配7张牌。 So I am creating a random number and then assigning the card at that nmber to a player. 因此,我创建了一个随机数,然后在该nmber处将纸牌分配给玩家。
for (int i = 0; i < 7; i++)
{
int r = rnd.Next(108);
if (vis[r] != 1) //vis[] is an array to checkk visited elements
{
// u[i] = Content.Load<Texture2D>("toString.Allcards[r]");
u[i]=Content.Load<Texture2D>(ToString("Allcards[r]"));
}
This is not working, please help. 这不起作用,请帮忙。
假设“ Allcards [r]”保存卡片的纹理(即,Allcards [1] ==“黑桃A”,并且在您的项目中有一个名为黑桃A的纹理),则可能需要这样:
u[i]=Content.Load<Texture2D>(Allcards[r]);
for (int i = 0; i < 7; i++)
{
int r = rnd.Next(108);
if (vis[r] != 1) //vis[] is an array to checkk visited elements
{
// u[i] = Content.Load<Texture2D>("toString.Allcards[r]");
u[i]=Content.Load<Texture2D>(Allcards[r].ToString());
}
}
You want Content.Load<Texture2D>(Allcards[r]);
您需要Content.Load<Texture2D>(Allcards[r]);
assuming that Allcards is an array of strings. 假设Allcards是一个字符串数组。 If Allcards is an array of Texture2D objects, then Content.Load
is unnecessary because you've already loaded it; 如果Allcards是Texture2D对象的数组,则不需要Content.Load
,因为您已经加载了它。 you can use u[i] = Allcards[r]
. 您可以使用u[i] = Allcards[r]
。
Having said that, you probably don't want to just give the texture to the player; 话虽如此,您可能不希望仅将纹理提供给播放器。 you'll want to give them the actual card. 您需要给他们实际的卡。 I'd suggest creating a Card class and assigning textures to that, along with some useful info like an ID, and maybe some properties to explain what it does. 我建议创建一个Card类并为其分配纹理,以及一些有用的信息(例如ID),以及一些属性来解释其作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.