ecoguy
ecoguy

Reputation: 665

Not allowed to use property observer

I want two SKSpriteNodes to be at the same position and static to each other. I first tried setting this up in the update() function.

sprite1.position = sprite2.position

It gives sprite1 the position of sprite2 one frame before. With high speeds (changes in sprite2's position ) it gets clear they are not static to each other. I then tried using a property observer:

sprite2.position = sprite2Position{ didSet{ sprite1.position = sprite2.position } }

I'm not allowed to do this. Xcode says I have to separate multiple statements on line.

Upvotes: 1

Views: 68

Answers (1)

user4233369
user4233369

Reputation:

To make sure the sprites have the same position, set the position after physics and SKActions have been simulated. Do this in the didFinishUpdate() method of SKScene:

override func didFinishUpdate() {
    sprite1.position = sprite2.position
}

Upvotes: 1

Related Questions