我无法从另一个类Menu.swift调用我的GameViewController.swift中的函数.我把这个函数称为:
class Menu: SKnode {
func scoreAction(sender:UIButton!) {
self.buttonPlay.removeFromSuperview()
self.buttonScore.removeFromSuperview()
// CALLING FUNCTION
GameViewController.showLeaderboard()
}
}
Run Code Online (Sandbox Code Playgroud)
这是我试图调用的函数:
class GameViewController: UIViewController,
UITextFieldDelegate, GKGameCenterControllerDelegate {
func showLeaderboard()
{
var gcViewController: GKGameCenterViewController = GKGameCenterViewController()
gcViewController.gameCenterDelegate = self
gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards
gcViewController.leaderboardIdentifier = "yourleaderboardid"
self.presentViewController(gcViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
}
我的Menu类中的编译器错误在GameViewController.showLeaderboard()中"参数#1在调用中缺少参数"但我不明白编译器期望的参数类型,因为我声明了函数而没有任何需要参数.
谢谢
我试图运行这段代码,但编译器在烦我Int不能转换为CGFloat,但我从来没有声明min,max或value作为变量'Int',也没有提到过它们.
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
bird.physicsBody.velocity = CGVectorMake(0, 0)
bird.physicsBody.applyImpulse(CGVectorMake(0, 8))
}
func clamp (min: CGFloat, max: CGFloat, value:CGFloat) -> CGFloat {
if (value > max) {
return max
} else if (value < min){
return min
}else{
return value
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
bird.zRotation = self.clamp(-1, max: 0.5, value: bird.physicsBody.velocity.dy * (bird.physicsBody.velocity.dy < 0 ?0.003 : 0.001 …Run Code Online (Sandbox Code Playgroud) 我正在玩游戏(SpriteKit-Swift).直到昨天我的设备运行正常,但今天我打开了Xcode,我的代码上出现了一堆编译器错误,即使是Xcode为你构建的自动代码也是错误.我设法通过创建一个新程序并将新的自动代码复制到我的程序来修复所有错误,我假设Apple改变了一些库.我的应用程序在iOS模拟器(5,5s,6,6 +)中完美运行但是当我在iPhone上运行应用程序时,应用程序崩溃,Xcode在编辑器(而不是控制台)中显示了这一点.
dyld`dyld_fatal_error:
0x120099088: brk #3 //MESSAGE POINTS HERE
Run Code Online (Sandbox Code Playgroud)
向第二行发送消息"威胁1:EXC_BREAKPOINT(代码= 1,subdued = 0x120099088)
还在另一个文件中显示:
dyld`_dyld_start:
0x120099000: mov x28, sp
0x120099004: and sp, x28, #0xfffffffffffffff0
0x120099008: movz x0, #0
0x12009900c: movz x1, #0
0x120099010: stp x1, x0, [sp, #-16]!
0x120099014: mov fp, sp
0x120099018: sub sp, sp, #16
0x12009901c: ldr x0, [x28]
0x120099020: ldr x1, [x28, #8]
0x120099024: add x2, x28, #16
0x120099028: adrp x4, -1
0x12009902c: mov x4, x4
0x120099030: adrp x3, 40
0x120099034: ldr x3, [x3, #880]
0x120099038: sub …Run Code Online (Sandbox Code Playgroud)