简体   繁体   中英

SKReferenceNode issue in iOS 11

I have found a strange issue starting with iOS 11 where my app will not update sprites on my SKReferenceNode. Basically, I have an "overlay" node (an SKS file that I use for multiple scenes) that has a header and footer. In the header, there is a score bar that expands when the player scores points. I am animating the score bar with an SKAction. Since iOS 11, the score bar does not appear. It happens both on the simulator and device. What's interesting is if I pause/resume the app through the debugger, the score bar immediately appears. I was able to strip down the issue to the following code.

import SpriteKit

var overlayNode:SKNode?
var header = SKSpriteNode()
var scoreBar:SKSpriteNode?
var scaleX:CGFloat = 0.3

class GameScene: SKScene {

    override func didMove(to view: SKView) {

         let path = Bundle.main.path(forResource: "SceneOverlay", ofType: "sks")
         let overlay = SKReferenceNode(url: URL(fileURLWithPath: path!))

        self.addChild(overlay)

        overlayNode = overlay.children.first

        header = overlayNode!.childNode(withName: "header") as! SKSpriteNode

        scoreBar = SKSpriteNode(imageNamed: "redBar")
        scoreBar?.position = CGPoint(x: 0, y: 0)
        scoreBar?.zPosition = 10
        scoreBar?.anchorPoint = CGPoint(x: 0, y: 0.5)
        scoreBar?.xScale = 0
        header.addChild(scoreBar!)
    }


    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        scaleX += 0.1
        let scoreBarExpand = SKAction.scaleX(to: scaleX, duration: 0.8)

        scoreBar!.run(scoreBarExpand)
        print ("Expanding score bar to \(scaleX)")

    }

}

The overlay SKS file is simply this:

SKS Overlay Image

If you run this code on an iOS 11 simulator or device, and tap on the screen, the score bar should appear and scale up by 10% each time you tap. However, you won't see anything. You can then pause and resume the app within the Xcode debugger, and the bar will immediately appear and expand. Again, this issue does not appear on an iOS 10 device/simulator.

Any thoughts on what's going on here?

Thanks in advance.

As I've pointed in some other scenarios, but they all point to the same issue. I've discovered a serious issue with iOS11 and SpriteKit. The Game Scene during the transition is getting paused automatically (but only in iOS11).

Knight0fDragon has also pointed out that it looks like the objects are getting paused on creation not during transition. Same result though.

After transitioning to the scene run

myScene.isPaused = false 

and it should fix the issue, and should have no adverse affects when the game is run on iOS10

I was having the same problem in my ObjC project. Knight0fDragons answer didn't work directly for me, but it inspired me.

Strangely first pausing and then unpausing worked for me.

    myScene.paused = YES;
    myScene.paused = NO;

Hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM