如何识别Swift代码中的连续用户触摸?连续我的意思是用户将手指放在屏幕上.只要用户触摸屏幕,我想将精灵套件节点移动到用户触摸的方向.
有没有一种简单的方法可以在Swift中绘制形状(最好使用Sprite-Kit),然后检测它们是否相交以及它们相交的位置?就像这里是一个相交的形状:
我是斯威夫特的noobie.我无法弄清楚为什么这段代码:
class GameScene: SKScene, SKPhysicsContactDelegate {
var statements = Statements()
override func didMoveToView(view: SKView) {
runAction(SKAction.repeatActionForever(
SKAction.sequence([
SKAction.runBlock(addLabel(statements)),
SKAction.waitForDuration(2.0)
])
))
}
func addLabel(statements: Statements) {...}
}
Run Code Online (Sandbox Code Playgroud)
结果:在调用中缺少参数"完成"的参数
我正在使用Sprite Kit绘图.我想检测用户的图纸何时相交.
我试图遵循代码,但它不起作用.似乎sprite kit没有保存所有点:
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
touch = touches.anyObject() as UITouch!
for drawingPoint in drawingPoints{
if(touch.locationInNode(self) == drawingPoint){println(true)}
}
drawingPoints.append(touch.locationInNode(self))
}
Run Code Online (Sandbox Code Playgroud) 我试图通过首先将 SKShapeNode 转换为纹理来将 SKShapeNode 转换为 Sprite 节点。然而结果是看不见的精灵。物理体通常在那里,但没有显示图形。我想我尝试转换 SKShapeNode 的方式有问题,但我想不出是什么。你知道出了什么问题吗?感谢所有帮助!
let createdShape = SKShapeNode(path: path)
createdShape.physicsBody = SKPhysicsBody(edgeLoopFromPath: createdShape.path)
createdShape.physicsBody?.categoryBitMask = PhysicsCategory.Shape
createdShape.physicsBody?.contactTestBitMask = PhysicsCategory.None
createdShape.name = "paintedArea"
createdShape.strokeColor = shapeBorderColor
createdShape.lineWidth = 5.0
createdShape.fillColor = shapeFillColor
createdShape.alpha = 1.0
createdShape.zPosition = shapeZPosition
let texture = view?.textureFromNode(createdShape)
println(texture?.description)
let sprite = SKSpriteNode(texture: texture)
sprite.physicsBody = createdShape.physicsBody
sprite.position = createdShape.position
sprite.color = UIColor.blueColor()
self.addChild(sprite)
Run Code Online (Sandbox Code Playgroud) 我对类方法调用有一个Swift noobie问题.我正在为我的孩子们使用Sprite Kit构建一个简单的学习应用程序.我在GameScene中定义了一个全局变量scoreCount,我几乎完成了所有游戏逻辑,例如检测正确答案和增加scoreCount.我也有GameOverScene.在两者上我都显示了分数 - 标签.我使用scoreCount参数(在GameScene中)保持得分.但是,由于我对Swift和Sprite Kit很陌生,我想知道如何在GameViewController中更新乐谱标签?所以基本上我想从GameScene调用GameViewController.updateLabels().
我知道这不是理想的方式,但请分享您的解决方案概念.谢谢!
为什么这个代码结果为"Type'CGPoint'不符合协议'AnyObject'"?
let mutableSet = NSMutableSet()
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
touch = touches.anyObject() as UITouch!
mutableSet.addObject(touch.locationInNode(self))
}
Run Code Online (Sandbox Code Playgroud) 好的,Swift 1.2发生了什么?我最近更新并突然发现我的项目全是红色的.是否已删除与NSSets的兼容性或什么?我该如何解决?
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
Run Code Online (Sandbox Code Playgroud)
结果:
Overriding method with selector 'touchesBegan:withEvent:' has incompatible type '(NSSet, UIEvent) -> ()'
Run Code Online (Sandbox Code Playgroud) swift ×8
sprite-kit ×6
ios ×4
skshapenode ×2
function ×1
global ×1
intersection ×1
nsmutableset ×1
skscene ×1
skspritenode ×1
typing ×1