我非常喜欢在XCode中编程并希望重新编程拖放游戏...到目前为止,代码如下所示...但是当我运行它时,函数“didMove”无法调用函数“setupDragLabel” .... walve打开调试器......我不知道我做错了什么......对此事的任何帮助都非常感谢!!!
pS:已经尝试了它而没有调用setupDragLabel并将代码直接复制到“didMove”......这样可行......但这只是解决问题的方法...所以我想知道为什么这样我现在这样做不起作用
import SpriteKit
import GameplayKit
class GameScene: SKScene {
let label1 = SKLabelNode()
let blueBin = SKSpriteNode()
let yellowBin = SKSpriteNode()
func setupDragLabel()
{
//set font and label and position of the label
label1.fontName = "Chalkduster";
label1.fontSize = 20
//label1.position = CGRectMake( 0.0, 0.0, 10.0, 10.0)
//get a random number between 0 and 1
let random = arc4random_uniform(2)
//depending on the random number set the text and name to either blue or yellow
if random == 0
{
label1.text = "blue"
label1.name = "blue"
}
else
{
label1.text = "yellow"
label1.name = "yellow"
}
// add the label to the scene
addChild(label1)
}
override func didMove(to view: SKView) {
setupDragLabel()
}