swift SpriteKit で画像を横にスライドした分だけx軸方向にスライドさせるプログラムを組みたいです。画像は表示されるのですが画像をドラッグすることができません。何が足りないのでしょうか?
import SpriteKit class GameScene: SKScene { var SelectBTN = SKSpriteNode() override func didMove(to view: SKView) { BTN() } func BTN(){ let SelectBTN = SKSpriteNode(imageNamed: "SelectWorldBTN1") SelectBTN.position = CGPoint(x: self.frame.width/5, y: self.frame.height/6*5) SelectBTN.size = CGSize(width: self.frame.width/10, height: self.frame.width/10) self.addChild(SelectBTN) } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { _ = touch.location(in: self) _ = self.SelectBTN.frame.midX } } 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 xTranslation = newPosition.x - oldPosition.x var originalX = SelectBTN.frame.midX originalX += xTranslation } } override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/06 23:14