我试图在用户点击屏幕时在屏幕上显示精灵。我正在使用Xcode提供的默认SpriteKit游戏,下面是我用来检测用户点击屏幕的方法。我遇到的问题是我经常点击屏幕,但精灵没有出现。任何想法为什么会这样?
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch in touches {
let sprite = SKSpriteNode(imageNamed:"mySprite")
sprite.xScale = 0.3
sprite.yScale = 0.3
let dotX = (drand48() * Double (view!.scene!.frame.size.width))
let dotY = (drand48() * Double (view!.scene!.frame.size.height))
print (dotX)
print (dotY)
sprite.position.x = CGFloat (dotX)
sprite.position.y = CGFloat (dotY)
self.addChild(sprite)
}
}