2014-10-22 2 views
0

touchesBegan 기능을 사용할 수 없습니다. 사용자가 노드를 터치하면 호출되지 않습니다.SKSpriteNode에서 터치 이벤트가 감지되지 않습니다.

import SpriteKit 

class SimpleButton: SKSpriteNode { 
    //called when the user taps the button 
    override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) { 
     println("touches began") 
    } 

    //called when the user finishes touching the button 
    override func touchesEnded(touches: NSSet!, withEvent event: UIEvent!) { 
     println("touches ended") 
    } 

    override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) { 
     println("touches moved") 
    } 
} 

답변

3

답변은 userInteractionEnabled 매개 변수를 사용하여 터치를 활성화해야합니다.

let imageTexture = SKTexture(imageNamed: "a_button") 
let sprite: SimpleButton = SimpleButton(texture: imageTexture) 

sprite.userInteractionEnabled = true // <--- This is required, it defaults to false. 

sprite.position = CGPoint(x:CGRectGetMidX(self.frame) - 200, y:CGRectGetMidY(self.frame)); 
sprite.color = UIColor.blackColor() 
sprite.colorBlendFactor = 1.0 
self.addChild(sprite) 
관련 문제