메인 GameScene.swift 파일과 facebookLogin.swift 파일이 있습니다.클래스 함수 호출
facebookLogin.Swift 파일의 클래스에서 SKSpriteNode 'FBButton'을 만들고 self.addChild (FBButton)를 통해 GameScene에 추가하려고합니다. 이 클래스는 touchBegan()과 facebookSignIn()이라는 두 가지 기능을 가지고 있습니다.
사용자가 'FBButton'스프라이트를 터치하면 touchBegan()이 버튼 터치를 인식하고 facebookSignIn()을 호출합니다. 이 기능은 Facebook 사용자에게 연결됩니다. 여기까지는 모든 것이 잘됩니다.
이 함수가 GameScene.swift에서 ShowButtons() 함수를 다시 호출하기를 원합니다. ShowButtons()는 ShowButtons()를 호출하여 FBLogin SpriteNode를 제거하고 2 개의 SpriteNodes를 추가하고 사용자 Facebook 데이터를 NSDictionary로 다운로드합니다.
데이터는 사용자 페이스 북에서 가져 오지만 버튼은 부모에서 제거되지 않은 FBButton을 생성하지 않습니다.
내가 잘못 될 곳을 알려주십시오. 다음은
class facebookLogin: SKNode {
var signedIn = false
override init() {
fbButton = SKSpriteNode(imageNamed: "login_with_facebook")
fbButton.xScale = 1.0
fbButton.yScale = 1.0
super.init()
addChild(fbButton)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let point = touch.locationInNode(self)
if fbButton.containsPoint(point) {
facebookSignin()
}
}
func facebookSignin() {
var permissions = ["user_about_me",
"user_birthday"];
PFFacebookUtils.logInWithPermissions(permissions, {
(user: PFUser!, error: NSError!) -> Void in
if user == nil {
NSLog("Uh oh. The user cancelled the Facebook login.")
self.signedIn = false
} else if user.isNew {
NSLog("User signed up and logged in through Facebook!")
self.signedIn = true
} else {
NSLog("User logged in through Facebook!")
self.signedIn = true
GameScene().ShowButtons()
}
})
}
}
는
class GameScene: SKScene {
let fbButton = facebookLogin()
var btnHostGame: SKSpriteNode = SKSpriteNode(imageNamed: "HostGame")
var btnJoinGame: SKSpriteNode = SKSpriteNode(imageNamed: "JoinGame")
override func didMoveToView(view: SKView) {
userInteractionEnabled=true
self.backgroundColor = SKColor.whiteColor()
self.fbButton.userInteractionEnabled = true
self.fbButton.position = CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.5)
addChild(self.fbButton)
}
func showButtons() {
self.btnHostGame.name = "btnHostGame"
self.btnHostGame.position = CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.6)
addChild(self.btnHostGame)
self.btnJoinGame.name = "btnJoinGame"
self.btnJoinGame.position = CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.40)
addChild(self.btnJoinGame)
fbButton.RemoveFromParent()
}
}
모두가 다시 GameScene을 호출 할 때를 제외하고 완벽하게 작동 쇼 버튼 스크립트입니다. 버튼이 나타나지 않고 FBButton이 제거되지 않습니다.
누구나 해결책을 알고 계십니까?
건배 Ryann는
()'당신이 GameScene''의 새로운 인스턴스를 작성에서
GameScene
를 발표, 기존 인스턴스에 접근하지당신이 호출 할 수있는이 방법은, . – zaph