我一直在做这个游戏,并为我的精灵继续前行,但每当我点击精灵跳跃时,地面逐渐加速,每次点击都会以一种荒谬的速度加速,我不想要它去做这个。我该如何解决?
这是我的代码:
类MCTGround:SKSpriteNode {
item
编辑:我的touchesBegan功能:
let numberOfSegments = 21
let colorOne = UIColor(red: 88.0/255.0, green: 148.0/255.0, blue:87.0/255.0, alpha: 1.0)
let colorTwo = UIColor(red: 120.0/255.0, green: 195.0/255.0, blue: 118.0/255.0, alpha: 1.0)
init(size: CGSize) {
super.init(texture: nil, color: UIColor.brownColor(), size: CGSizeMake(size.width * 2, size.height))
anchorPoint = CGPointMake(0, 0.5)
for var i = 0; i < numberOfSegments; i++ {
var segmentColor: UIColor!
if i % 2 == 0 {
segmentColor = colorOne
} else {
segmentColor = colorTwo
}
let segment = SKSpriteNode(color: segmentColor, size: CGSizeMake(self.size.width / CGFloat(numberOfSegments), self.size.height))
segment.anchorPoint = CGPointMake(0.0, 0.5)
segment.position = CGPointMake(CGFloat(i) * segment.size.width, 0)
addChild(segment)
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func start() {
let moveLeft = SKAction.moveByX(-frame.size.width / 2, y: 0, duration: 1.0)
let resetPosition = SKAction.moveToX(0, duration: 0)
let moveSequence = SKAction.sequence([moveLeft, resetPosition])
runAction(SKAction.repeatActionForever(moveSequence))
}
}
答案 0 :(得分:0)
这是因为您每次都会向后台添加其他操作。只是做:
var hasBegun = false
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
jumpPlayer()
if !hasBegun {
hasBegun = true
movingGround.start()
fruitGenerator.startGeneratingFruitEvery(3)
}
...
或仅运行那些&#34; start&#34; -type方法一次的任何其他方法。