スライドすると上から下にWorld1fieldを動かし、一番下、もしくは一番上、つまり画像の縦幅を超えないように動かしたいです。どうs修正すべきでしょうか?
import SpriteKit class GameScene: SKScene { let World1field = SKSpriteNode(imageNamed: "World1field") override func didMove(to view: SKView) { createWorld1field() } func createWorld1field(){ World1field.size = CGSize(width: self.frame.width, height: self.frame.height*2) World1field.position = CGPoint(x: self.frame.width/2, y: self.frame.height) self.addChild(World1field) } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches{ _ = touch.location(in: self) } } override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){ for touch in touches { let newPosition = touch.location(in: self) let oldPosition = touch.previousLocation(in: self) let yTranslation = newPosition.y - oldPosition.y var originalY = World1field.frame.midY originalY += yTranslation if World1field.frame.maxY>self.frame.height{ World1field.run(SKAction.moveTo(y: originalY, duration: 0.0)) } if World1field.frame.minY<0{ World1field.run(SKAction.moveTo(y: originalY, duration: 0.0)) } } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。