Moving a SKSpriteNode
image in response to a change in its position is not working.
Based on the code below, does anyone have an idea why?
N.B. I change the position of the image within my class GameScene
.
Then, I call, e.g., this function:
func drawBall() {
let positionInSceneCoordinates = CGPoint(x: ballPosX, y: ballPosY)
myBall!.removeAction(forKey: "moveTO")
let moveTO = SKAction.move(to: positionInSceneCoordinates, duration: TimeInterval(1))
myBall!.run(moveTO, withKey: "moveTO)")
}
Selective placement of print
statements prove that the ballPosX, ballPosY
are changing as they should, but I am observing zero movement on the Xcode Simulator via the call to myBall!run(..)
.
I am at a loss here on how to proceed.
Thanks bunches!
The solution to making the SKSpriteNodes,
myPaddle + myBall,
move was to delete them from my GameScene.sks
file so this file would not load them.
But rather, use GameViewController's addGamePiecesToScene()
to load them via:
-
set their
.zPosition,
.size
+.position
-
SKScene.addChild(SKSpriteNode!)
Once the above code changes were inserted, the two Game Pieces started moving in response to my game controller.