Swift : 变换 SKSpriteNode
Swift : Transform SKSpriteNode
我正在尝试为 UIView 但为 SKSprite 节点实现此代码:
stopIcon.transform = CGAffineTransformMakeScale(0.01, 0.01)
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.stopIcon.transform = CGAffineTransformMakeScale(1.0, 1.0)
})
我的SKSprite节点是这样设置的:
stopIcon = SKSpriteNode(imageNamed: "StopIcon")
stopIcon?.size = CGSize(width: ((stopImage?.size.width)! * 0.75), height: ((stopImage?.size.height)! * 0.75))
stopIcon?.position = CGPoint(x: self.size.width * 0.22, y: self.size.height * 0.91)
self.addChild(stopIcon!)
谢谢大家
我猜你想在 0.5 秒内缩放 SKSpriteNode,从 0.1 -> 1.0(原始比例的十分之一到完整比例)。
使用 SpriteKit 的 SKAction class 可以这样实现:
//set the inital scale of node to 0.1
stopIcon.setScale(0.1)
//create action to scale skspritenode to scale of 1.0 over 0.5 seconds.
let scaleAction = SKAction.scaleTo(1.0, duration: 0.5)
//call on the action.
stopIcon.runAction(scaleAction)
我正在尝试为 UIView 但为 SKSprite 节点实现此代码:
stopIcon.transform = CGAffineTransformMakeScale(0.01, 0.01)
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.stopIcon.transform = CGAffineTransformMakeScale(1.0, 1.0)
})
我的SKSprite节点是这样设置的:
stopIcon = SKSpriteNode(imageNamed: "StopIcon")
stopIcon?.size = CGSize(width: ((stopImage?.size.width)! * 0.75), height: ((stopImage?.size.height)! * 0.75))
stopIcon?.position = CGPoint(x: self.size.width * 0.22, y: self.size.height * 0.91)
self.addChild(stopIcon!)
谢谢大家
我猜你想在 0.5 秒内缩放 SKSpriteNode,从 0.1 -> 1.0(原始比例的十分之一到完整比例)。
使用 SpriteKit 的 SKAction class 可以这样实现:
//set the inital scale of node to 0.1
stopIcon.setScale(0.1)
//create action to scale skspritenode to scale of 1.0 over 0.5 seconds.
let scaleAction = SKAction.scaleTo(1.0, duration: 0.5)
//call on the action.
stopIcon.runAction(scaleAction)