加大节点的攻丝面积。 ios swift

Enlarge tapping area for node. ios swift

我做了简单的游戏,但是为了更容易玩我想扩大节点区域来点击。现在我已经让苍蝇在随机路径上飞行,当它们飞行时我想点击它。但是现在因为节点半径太小,很难点击它。

这里我正在创建精灵,并且一直保持五的计数。

func updateFlyCount() {
    if  nodeCount < 5 {
        self.addFly()
    }
}


func addFly() {

    // Create sprite
    let fly = SKSpriteNode(imageNamed: "fly")
    fly.name = "fly"

    // Add the fly to the scene
    addChild(fly)

    // Determine speed of the fly
    let actualDuration = random(min: CGFloat(1.5), max: CGFloat(5.0))

    var pointWhereToStart: CGPoint = CGPointMake(0, screenSize.height)

    let randomSide = round(random(min: 1, max: 3))
    print("randomside made\(randomSide)")
    if randomSide == 1 {
        let randomStartingPoint = random(min: screenSize.height * 0.5, max:  screenSize.height)
        pointWhereToStart = CGPointMake (0, randomStartingPoint)
    } else if randomSide == 2 {
        let randomStartingPoint = random(min: 0, max:  screenSize.width)
        pointWhereToStart = CGPointMake (randomStartingPoint, screenSize.height)
    } else if randomSide == 3 {
        let randomStartingPoint = random(min: screenSize.height * 0.5, max:  screenSize.height)
        pointWhereToStart = CGPointMake (screenSize.width, randomStartingPoint)
    }

    let randomPoint1x = random(min: 0, max: screenSize.width)
    let randomPoint2y = random(min: 0, max: screenSize.height)
    let randomPoint3x = random(min: 0, max: screenSize.width)
    let randomPoint4y = random(min: 0, max: screenSize.height)

    let cgpath: CGMutablePathRef = CGPathCreateMutable()
    let startingPoint: CGPoint = pointWhereToStart
    let controlPoint1: CGPoint = CGPointMake(randomPoint1x, randomPoint2y)
    let controlPoint2: CGPoint = CGPointMake(randomPoint3x, randomPoint4y)
    let endingPoint: CGPoint = CGPointMake(screenSize.width * 0.5, screenSize.height * 0.5)
    CGPathMoveToPoint(cgpath, nil, startingPoint.x, startingPoint.y)
    CGPathAddCurveToPoint(cgpath, nil, controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, endingPoint.x, endingPoint.y)
    let enemyCurve: SKAction = SKAction.followPath(cgpath, asOffset: false, orientToPath: false, duration: NSTimeInterval(actualDuration))
    fly.runAction(SKAction.sequence([SKAction.waitForDuration(0.5), enemyCurve]))

    updateFlyCount()
}

这是我删除节点的方法

 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch: AnyObject in touches {
        print("tapped")
        let touchLocation = touch.locationInNode(self)
        let touchedNode = self.nodeAtPoint(touchLocation)

        if (touchedNode.name == "fly") {
            touchedNode.removeFromParent()
            addFly()
        }
    }
}

创建一个您想要的大小的 SKNode,然后将 SKSpriteNode 作为子节点添加到它。

然后在您的 touchesBegan 中检查是否击中了 SKNode 而不是精灵。

你必须运行针对 SKNode 而不是 fly 的动作。