Reputation: 117
I'm trying to create an application where an image is increasing in size and want to change the rate in which it does/be able to touch for a function. I'm new to Swift, thank you for anyone who helps. This is within "Game" applications of Xcode -- Code:
class GameScene: SKScene {
let image = SKSpriteNode(imageNamed: "Circle-icon")
let num = 1
var grow = 0
override func didMove(to view: SKView) (
let bg = SKSpriteNode(imageNamed: "background")
bg.size = self.size
bg.position = CGPoint(x: self.size.width/2, y: self.size.height/2) bg.zPosition = 0
self.addChild(bg)
image.position = CGPoint(x: self.size.width/2, y: self.size.height * 0.2)
image.zPosition = 1
while grow < 10 {
let growMore = grow
image.setScale(CGFloat(growMore))
grow += 0.1
}
self.addChild(image)
}
}
Upvotes: 0
Views: 154
Reputation: 3158
Run an SKAction
on the sprite you wish to scale. This example scales it to size 300x300 over a period of five seconds, but obviously you'd want to adjust that to your liking.
let scale = SKAction.scale(to: CGSize(width: 300, height: 300), duration: 5.0)
yourSprite.run(scale)
You can also scale by increments by using the separate scale method with different constructor scale(by: )
Upvotes: 1