我想知道是否有办法根据其位置缩放精灵节点?
因此,例如当角色y位置增加时,你希望他看起来更小,就像他走得更远。当他的y位置减少时,你希望他越接近你就越大。
let swipeUp = UISwipeGestureRecognizer()
override func didMoveToView(view: SKView) {
swipeUp.addTarget(self, action: "swipedUp")
swipeUp.direction = .Up
self.view!.addGestureRecognizer(swipeUp)
swipeDown.addTarget(self, action: "swipedDown")
swipeUp.direction = .Down
self.view!.addGestureRecognizer(swipeDown)
addSprite()
}
func swipedUp(){
let amountToMove: CGFloat = 100
let move: SKAction = SKAction.moveByX(0, y: amountToMove, duration: 0.1)
character.runAction(move)
}
func swipedDown(){
let amountToMove: CGFloat = 100
let move: SKAction = SKAction.moveByX(0, y: -amountToMove, duration: 0.1)
character.runAction(move)
}
func addSprite(){
let sprite = SKSpriteNode(imageNamed: "testImage")
sprite.position = CGPoint(x: xPos, y: yPos)
}
答案 0 :(得分:1)
覆盖精灵位置属性并在其中设置比例因子。这是一个非常基本的例子,您需要根据y确定您的比例因子实际是什么。
override var position{
didSet{
self.setScale((screen.height - y) / (screen.height / 2))
}
}