Moving a SKSpriteNode image in response to a change in its position

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!

Answered by JohnLove in 744318022

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:

  1. set their .zPosition, .size + .position

  2. SKScene.addChild(SKSpriteNode!)

Once the above code changes were inserted, the two Game Pieces started moving in response to my game controller.

Meaningful EDIT of my above Post:

Within AppDelegate I have;

var myBall: SKSpriteNode?

Within my `GameViewController, I have:

myBall = SKSpriteNode(texture: SKTexture(imageNamed: ballImg))

Meaningful EDIT of the above Post:

Within my AppDelegate I have: var myBall: SKSpriteNode?

Within my GameViewController I have: myBall = SKSpriteNode(texture: SKTexture(imageNamed: "dinossaur.png"))

Thanks for your patience.

A significant addition =

I converted the specified Scene coordinates to Screen coordinates and set myBall.position = the new Screen coordinates. Plus I deleted the SKAction pair of statements.

But, still no visible movement of the SKSpriteNode = myBall.

As stated above, I am really at a loss on the solution.

And, again, Thanks in Advance!

Accepted Answer

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:

  1. set their .zPosition, .size + .position

  2. SKScene.addChild(SKSpriteNode!)

Once the above code changes were inserted, the two Game Pieces started moving in response to my game controller.

Moving a SKSpriteNode image in response to a change in its position
 
 
Q