我正在创建一个应用,要求玩家根据屏幕中心的箭头指向的方式向左或向右倾斜手机。我想访问陀螺仪,然后记录答案并触发显示下一个箭头。
import SpriteKit
import CoreMotion
class Arrow: SKSpriteNode { }
class GameScene: SKScene {
var arrows = ["arrowleft1","arrowright1", "arrowmix1","arrowmix2"]
override func didMove(to view: SKView) {
let background = SKSpriteNode(imageNamed: "background")
background.position = CGPoint(x: frame.midX ,y: frame.midY)
background.alpha = 0.2
background.zPosition = -1
addChild(background)
let arrowType = arrows.randomElement()!
let arrow = Arrow(imageNamed: arrowType)
arrow.position = CGPoint(x: frame.midX, y: frame.midY)
arrow.name = arrowType
arrow.zPosition = 1
addChild(arrow)
}
}
override func update(_ currentTime: TimeInterval) {
}
目标是:
陀螺仪/加速键检测手机向左/向右移动
触发功能可保存答案并生成新箭头,直到记录了20个提交为止