SKAction.moveBy不起作用,我不知道为什么

问题描述 投票:0回答:1

我一直在关注Jared Davidson的教程How to make Flappy Bird,我不知道为什么使用SKAction.moveBy的其中一个函数不起作用。我认为部分问题在于它可能处于横向模式。用户应该触摸屏幕,导致鬼魂跳跃和障碍物开始移动。有人请帮忙。这是我的一个函数的代码:

 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
    if (gameStarted == false)
    {
        gameStarted = true
        let spawn = SKAction.run(
        {
            () in

            self.createObstacles()
        })

        let delay = SKAction.wait(forDuration: 2.0)
        let spawnDelay = SKAction.sequence([spawn, delay])
        let spawnDelayForever = SKAction.repeatForever(spawnDelay)
        self.run(spawnDelayForever)

        let distance = CGFloat(self.frame.width + 20)
        let moveObstacles = SKAction.moveBy(x: distance, y: 0, duration: TimeInterval( 0.01*distance))
        let removeObstacles = SKAction.removeFromParent()
        moveAndRemove = SKAction.sequence([moveObstacles, removeObstacles])

        ghost.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
        ghost.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 90))


    }
    else
    {
        ghost.physicsBody?.velocity = CGVector(dx: 0, dy: 0)
        ghost.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 90))
    }

}
swift xcode gamekit
1个回答
1
投票

我刚刚遇到了同样的问题,并且能够通过移动来解决它

    let wallDistance = CGFloat(self.frame.size.width + wallPair.frame.width)
    let moveWall = SKAction.moveBy(x:  -wallDistance, y: 0, duration: 
            TimeInterval(0.008 * wallDistance))
    let removeWall = SKAction.removeFromParent()
    moveAndRemove = SKAction.sequence([moveWall, removeWall]) 

在createWalls内部创建顶部和底部墙的位置下方。我把它放在setScales下面。

然后你添加

    wallPair.run(moveAndRemove)

在哪里添加topWall和bottomWall作为子项。

© www.soinside.com 2019 - 2024. All rights reserved.