我做了简单的游戏,但为了更容易玩,我想扩大点击的节点区域。现在我已经让苍蝇在随机路径上飞行,当它们飞行时我想点击它。但是现在由于节点半径太小,很难挖掘它。
我在这里创建 Sprite ,并一直保持数到五。
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而不是 Sprite 被击中。
您必须针对 SKNode 而不是苍蝇运行该操作。
关于ios - 加大节点的攻丝面积。 ios swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35549724/