GameplayKit

2016-06-28  本文已影响0人  四毛哥掉落的鳞片

1. It can shuffle an array. Like in the FlagGame, we want to show up 3 different country flags, one way is to shuffle the array and the pick the first 3.

2. It has a special method called nextIntWithUpperBound(), which lets you specify a number as your "upper bound" – i.e., the cap for the numbers to generate. GameplayKit will then return a number between 0 and one less than your upper bound, so if you want a number that could be 0, 1 or 2 you specify an upper bound of 3.

to generate a random number between 0 and 2 inclusive:

var correctAnswer = 0

correctAnswer = GKRandomSource.sharedRandom().nextIntWithUpperBound(3)

上一篇 下一篇

猜你喜欢

热点阅读