gpt4 book ai didi

swift 类型类没有成员函数

转载 作者:可可西里 更新时间:2023-11-01 00:58:27 35 4
gpt4 key购买 nike

我创建了这个函数 sayHello,它每 4 秒调用一次。代码是:

_ = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: #selector(GameScene.sayHello(_:)), userInfo: nil, repeats: true)

}
func sayHello(Enem: SKSpriteNode) {
}

然而,当我向这个函数添加一个变量 Enem 时:

 _ = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: #selector(GameScene.sayHello(_:)), userInfo: nil, repeats: true)
sayHello()

}
func sayHello() {

let array = [Enemy(imageNamed: "Slide 2"),Enemy(imageNamed: "Slide 1"),Enemy(imageNamed: "Slide 3"),Enemy(imageNamed: "Slide 4"),Enemy(imageNamed: "Slide 5"),Enemy(imageNamed: "Slide 6"),Enemy(imageNamed: "Slide 7"),Enemy(imageNamed: "Slide 8"),Enemy(imageNamed: "Slide 9"),Enemy(imageNamed: "Slide 10")]
var level0 = Enemy(imageNamed: "Slide 1")
let level2 = SKSpriteNode(imageNamed: "Slide 2")
let level3 = SKSpriteNode(imageNamed: "Slide 3")
let level4 = SKSpriteNode(imageNamed: "Slide 4")
let level5 = SKSpriteNode(imageNamed: "Slide 5")
let level6 = SKSpriteNode(imageNamed: "Slide 6")
let level7 = SKSpriteNode(imageNamed: "Slide 7")
let level8 = SKSpriteNode(imageNamed: "Slide 8")
let level9 = SKSpriteNode(imageNamed: "Slide 9")
let level10 = SKSpriteNode(imageNamed: "Slide 10")
var touchLocation = CGPoint?()
var slide = arc4random_uniform(10)
let level1 = Int(arc4random_uniform(UInt32(array.count)))
let Enem = array[level1]
//moveEnem(Enem)
(string: "\(level1)")

print("sayhdkl")
Enem.position = CGPoint(x: 540, y: 320 )
Enem.physicsBody = SKPhysicsBody(texture: Enem.texture!, size: Enem.size)
Enem.physicsBody?.dynamic = true
Enem.physicsBody?.categoryBitMask = BodyType.level1
Enem.physicsBody?.collisionBitMask = 0
Enem.zPosition = 12
addChild(Enem)

我在线上遇到错误

_ = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: #selector(GameScene.sayHello(_:)), userInfo: nil, repeats: true)

它说类型游戏场景没有成员 sayHello。有人可以解释为什么现在会发生这种情况,因为我很困惑。

最佳答案

你需要改变你的选择器语法,你的函数没有参数所以你需要这样写选择器。

NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: #selector(GameScene.sayHello()), userInfo: nil, repeats: true)

关于swift 类型类没有成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39465996/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com