SpriteKit: Passing data between scenes

前端 未结 6 796
无人共我
无人共我 2020-12-09 13:04

I am stuck trying to pass data between scenes \"SKScene\" in SpriteKit. For instance I would like to pass the score from level A to Level B.

Maybe the solution is ar

6条回答
  •  抹茶落季
    2020-12-09 13:21

    Apple documentation states that userData is the way to go for storing node specific data here in Sprite Kit Best Practices

    Use the userData property on nodes to store game-specific data, especially if you are not implementing your own subclasses.

    Therefore I would accept @doctorBroctor's answer as the correct one for when using Sprite Kit natively.

    However, you should remember to initialize userData for the target node before setting a value as @LearnCocos2d points out in this answer. You can do this inside initWithSize: method of the SKScene subclass you are about to transition into.

提交回复
热议问题