【发布时间】:2016-03-22 20:00:30
【问题描述】:
在我之前的应用程序(单视图应用程序)中,我在 IBActions 中使用 touch down 和 touch up 来获取游戏中的按钮。但是在 SpriteKit 游戏中,您必须完全创建场景,而且我很难编写 touchesBegan 方法。
这是我的基本运动方法/功能:
func heroMovementLeft () {
hero.position = CGPointMake(hero.position.x - 0.5,hero.position.y);
}
这是我的左箭头节点,我希望在触摸左箭头时调用 HeroMovementLeft 方法
func LeftArrow () {
let LeftArrow = SKSpriteNode(imageNamed: "Left Arrow.png")
LeftArrow.position = CGPointMake(30, 30)
self.addChild(LeftArrow)
}
这里是我现在编写touchesBegan 方法的地方
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch in touches {
}
}
我要创建一个 if 语句吗?我是否让 touch 成为变量?我需要在我的 touches started 方法中写什么,以便我的英雄在左箭头被触摸时会移动。我在网上查遍了,找不到这个问题的答案,请帮忙。
【问题讨论】:
-
有几条路可以走。最简单的方法是为要移动的节点命名,并在 touchesBegan 方法中使用
nodeAtPoint查看“如果您正在触摸正确的节点”...
标签: ios swift cocoa-touch sprite-kit touchesbegan