SKSpriteNode是否识别手势



我建了一堵墙,砖块没有移动,但我需要其中一个调用一些信息。 下面的代码在函数内部 可能应该有这个砖全局

    let brk = SKSpriteNode(imageNamed: imgName)
    if (imgName == "brickinfo"){
        brk.name = "brickinfo"
    }

    brk.position = CGPoint(x:CGRectGetMinX(self.frame)+brkx, y: CGRectGetMinY(self.frame)+brky)
    if (imgName == "brickinfo"){
        let singleTap = UITapGestureRecognizer(target: self, action: Selector("ShowInfo"))
        singleTap.numberOfTapsRequired = 1
        brk.userInteractionEnabled = true
        //brk.addGestureRecognizer(ShowInfo) //do not exist
    }
    brk.xScale = 0.2
    brk.yScale = 0.2
    addChild(brk)

我对其他移动图像使用相同的代码,这意味着它们具有SKAction,因此当我单击它们时,会触发触摸开始。 它们都使用相同的代码,添加一个名称,addchild()。

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
   /* Called when a touch begins */
    for touch in touches {
        let location = touch.locationInNode(self)
        //675
        //30
        print(self.nodeAtPoint(location).name)
        if let theName = self.nodeAtPoint(location).name {

但是"brickinfo"的名字总是归零。这个砖头形象能开始吗?谢谢

好吧,我不是在寻找手势,我想我需要添加手势来触发图像,但我只需要让这个图像用它的名字响应。经过 3-4 天的研究,我找到了解决方案,这很容易,zposition 不是为这个特定的砖设置的。当然,这带来了自己的问题。对不起,问题的标题。xcode 是否带有 3D 的 zposition 层视图?谢谢

最新更新