func increaseSnakeLength(){
snakeArray.append(snakeLength)
inc += snakeBody.size.height
if snakeMovingLeft == true{
snakeLength = SKSpriteNode(texture: nil, color: UIColor.blueColor(), size: CGSizeMake(20, 20))
snakeLength.position = CGPointMake(snakeBody.position.x + inc, snakeBody.position.y)
addChild(snakeLength)
}
if snakeMovingRight == true{
snakeLength = SKSpriteNode(texture: nil, color: UIColor.blueColor(), size: CGSizeMake(20, 20))
snakeLength.position = CGPointMake(snakeBody.position.x - inc, snakeBody.position.y)
addChild(snakeLength)
}
if snakeMovingUp == true{
snakeLength = SKSpriteNode(texture: nil, color: UIColor.blueColor(), size: CGSizeMake(20, 20))
snakeLength.position = CGPointMake(snakeBody.position.x, snakeBody.position.y - inc)
addChild(snakeLength)
}
if snakeMovingDown == true{
snakeLength = SKSpriteNode(texture: nil, color: UIColor.blueColor(), size: CGSizeMake(20, 20))
snakeLength.position = CGPointMake(snakeBody.position.x, snakeBody.position.y + inc)
addChild(snakeLength)
}
}
func moveSnake(){
if snakeArray.count > 0{
snakeLength.position = CGPointMake(snakeBody.position.x, snakeBody.position.y)
}
snakeBody.position = CGPointMake(snakeHead.position.x, snakeHead.position.y)
snakeHead.position = CGPointMake(snakeHead.position.x + snakeX, snakeHead.position.y + snakeY)
}
[贪吃蛇游戏] [1] [1]:http://i.stack.imgur.com/nhxSO.png有麻烦移动我的skspritenodes编辑:
我的功能increaseSnakeLength()增加了一个新的snakeLength块到现场的时候,黑鱼,使我接触食品。然后在我的moveSnake()函数中移动蛇块,但是当我移动snakeLength块时,它只会移动最新的块并使旧块不移动。你可以在上面的图片中看到这个。我不知道如何同时移动所有的snakeLength块。
蛇只能向上/向下/向左/向右移动,还是可以以任何角度移动? – 0x141E
蛇只根据滑动的方向左右移动/上/下移动 – user3856516