Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用多个图像并随机显示_Objective C - Fatal编程技术网

Objective c 使用多个图像并随机显示

Objective c 使用多个图像并随机显示,objective-c,Objective C,我如何使它随机显示什么图像,以便每次都显示不同的图像。这是我的代码,我想添加一些随机图像,例如“tutorial2.png”和“tutorial3.png”。我将在何处将它们添加到这行代码中,以便随机显示哪一行。我也没有太多的经验,所以细节和代码将不胜感激,谢谢 self.help=[CCSprite spriteWithFile:@"tutorial.png"]; self.help.position=ccp(ws.width/2,ws.height*4/4/2); [self addChil

我如何使它随机显示什么图像,以便每次都显示不同的图像。这是我的代码,我想添加一些随机图像,例如“tutorial2.png”和“tutorial3.png”。我将在何处将它们添加到这行代码中,以便随机显示哪一行。我也没有太多的经验,所以细节和代码将不胜感激,谢谢

self.help=[CCSprite spriteWithFile:@"tutorial.png"];
self.help.position=ccp(ws.width/2,ws.height*4/4/2);
[self addChild:self.help];

首先将图像添加到数组中,例如:数组

然后使用下面的代码获得随机索引

NSUInteger randomIndex = arc4random() % [theArray count];
那么


有很多随机的问题。你试了什么?@Larme嗯,我什么都没试过,因为我还没找到要试的东西。我不确定人们是否过度考虑了我要做的事情,但我再清楚不过了。我只是想让游戏随机选择3个图像中的一个,以便在每次显示带有此图像的屏幕时显示。我想这会很简单,只需要用逗号分开,比如spriteWithFile:@“tutorial.png”,“tutorial2.png”…等等。但这不起作用。任何帮助都是非常感谢的,因为我不是任何类型的专家。谢谢如果对象数不是2的幂,则arc4random不是最佳值。进一步信息:老实说,我不知道这意味着什么,数组是什么,如何以及为什么要向其中添加图像?我能不能用一个更简单的方法在这行代码中添加一些图像?
self.help=[CCSprite spriteWithFile:[NSString stringWithFormat:@"%@",[theArray[i]]]];
self.help.position=ccp(ws.width/2,ws.height*4/4/2);
[self addChild:self.help];