swift - 如何在 Sprite Kit 中使用 SKAction 永远重复缩放对象

标签 swift sprite-kit

我想不断增加屏幕上节点的高度,为了实现我创建了一个 SKAction 来缩放 Y,并且他们在其中永远重复,用户触摸屏幕后,代码如下:

var increaseSize = SKAction.scaleYTo(CGFloat(1.5), duration: 0.5)

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        /* Called when a touch begins */
        //BRIDGE is a rectangular SKSpriteNode        

        for touch: AnyObject in touches {
          bridge.runAction(SKAction.repeatActionForever(increaseSize)) //BRIDGE is a rectangular SKSpriteNode   

        }
    }

假设 bridge 的高度为 100,触摸屏幕后高度将为 150,这意味着 increaseSize 操作仅运行一次。

最佳答案

使用+ scaleXBy:y:duration: :

let increaseSize = SKAction.scaleXBy(1, y: CGFloat(1.5), duration: 0.5)

... // the rest of your code (no need to change it)

scaleYTo 操作会将节点缩放到 y 大小 1.5一次,然后继续将其从原始大小的 1.5 无限缩放到 1.5,这根本不执行任何操作. scaleXby:y:duration: 操作将增加相对比例,因此会一直缩放它。

关于swift - 如何在 Sprite Kit 中使用 SKAction 永远重复缩放对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26941422/

相关文章:

ios - 如何使用 Sprite 套件中的SKEmitterNode来实现 "fog of war"效果?

swift - 从 GameScene 隐藏 UIButton

ios - 由于授权,WKWebview 无法加载 Assets 文件

ios - 从 Swift Decodables 访问枚举的合适方法是什么?

ios - 无法将类型 '[PHAsset]' 的值分配给类型 'UIImageView!'

ios - 在 Sprite Kit 中使用 SKActionTimingFunction

ios - SpriteKit : callback when scene is done presenting?

arrays - SKSpritenode数组展示

objective-c - CGrect NSArray 错误

ios - Swift 允许扩展除一个以外的所有单元格?