Xcode 9: SKEditorReference doesn't allow animation?

I cannot get sprite instances that were added by reference (drag one sks file to another sks file in Xcode 9) for animation. This seems valid, since you can physically do such a thing, but I'm not sure why the auxiliary nodes are not expecting.

Example 1. Start with the standard spritekit template 2. add the HUD.sks file and add a color sprite somewhere, name it "hudSpriteNode" 3. drag the HUD.sks file into the GameScene.sks scene - center it to zero 4. Find hudSpriteNode ( by name) 5. Move it using .position (works!) 6. Move it using animation (crash!)

Help???

HUD.sks HUD.sks screenshot

GameScene.sks GameScene.sks screenshot

Add this code to GameScene.swift

if let testSpriteNode = childNode(withName: "//hudSpriteNode") as? SKSpriteNode { print("Found test sprite node") print("Test node position 1: \(testSpriteNode.position)") testSpriteNode.position = CGPoint.zero print("Test node position 2: \(testSpriteNode.position)") testSpriteNode.run(SKAction.moveBy(x: 200, y: 200, duration: 4)) } 

Run ... the position has been moved correctly, but the animation does not work.

+1
source share
1 answer

See the @Marcel link in the comments. The message he pointed out to me basically did the trick with some additional updates / validation on my part. The only way I was able to get this to work was to put isPaused in the exact sprite of the node I was trying to animate (in my ref node).

I tried isPaused = false at the top level, the main scene didMove to view, but with no effect, and then added isPaused = false to the main node link, no effect. It worked only when I added isPaused = false the actual sprite (in the ref node I added), I tried to revive. I removed isPaused = false from the main and ref nodes, and as long as isPaused = false was still in the node sprite question (the one that was in the ref node that I was trying to animate): success.

The bottom line seems that isPaused = false is required for any sprites contained in the referenced nodes.

+2
source

Source: https://habr.com/ru/post/1273828/


All Articles