SpriteKit: SKSpriteNodes disappears from SKEffectNode after a few seconds

I am working on the effect of metaballs in SpriteKit. I have a SKEffectNode with a shader that compresses the color range of its buffer. This effectnode has a hundred odd characters in its child SKSpriteNode. The effect works fine for a couple of seconds, but suddenly, for several frames, all spritonodes disappear from the screen, and the nodal step drops from 100 seconds down to 2 (I think the remaining 2 are the effect itself and the edge chain, which forms a container for holding balls?)

If I add spritenodes balls directly to the root of the scene, this will not happen. This only happens when they are created by children from the effect that they seem aggressively rejected after a few seconds.

Interestingly, (and this can be seen in the simulator, if the frame rate is quite low), SpriteNodes seems to be selected in the vertical order that they currently display on the screen, from the top of the screen to the bottom.

If the showsPhysics view property is set to true, I see that the SKSpriteNode physical bodies are still on the screen and are rolling. But their visual representation has disappeared, and the node account has been exhausted. According to the documents showsNodeCount "shows the physical bodies that are visible on the scene." Since the nodes are no longer visible, the node counter has fallen.

Does anyone know what could be causing this, or what tools can I use to debug it?

Standard SpriteKit iOS Swift 2.2 Xcode 7 template, replace the GameScene file with the following:

 import SpriteKit class GameScene: SKScene { override func didMoveToView(view: SKView) { // create walls to contain balls let box = SKPhysicsBody(edgeLoopFromRect: CGRect(x: 0, y: 0, width: 800, height: 800)) let boxNode = SKNode() boxNode.physicsBody = box addChild(boxNode) let radius: CGFloat = 5 let texture = createMetaballTexture(radius) let centre = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2) let rows = 12 let columns = 10 let metaballs = SKEffectNode() let shaderString = [ "void main()", "{", "vec4 c = texture2D(u_texture, v_tex_coord);", "gl_FragColor = smoothstep(0.3, 0.6, c); ", "}"].joinWithSeparator("\n") let map = SKShader(source: shaderString) metaballs.shader = map for i in 0...(rows * columns) { let ball = SKSpriteNode(texture: texture) let body = SKPhysicsBody(circleOfRadius: radius) body.friction = 0.1 body.restitution = 0.8 ball.physicsBody = body ball.position = CGPoint(x: centre.x + CGFloat(i % columns) * radius, y: centre.y + CGFloat(i / rows) * radius) ball.blendMode = .Add metaballs.addChild(ball) // change this to "addChild(ball)", and the nodes don't get culled } addChild(metaballs) physicsWorld.speed = 0.2 backgroundColor = SKColor.darkGrayColor() } func createMetaballTexture(radius: CGFloat) -> SKTexture { let metaballScale: CGFloat = 8 let ellipseOrigin = (metaballScale / 2) - 1.5 UIGraphicsBeginImageContext(CGSize(width: radius * metaballScale, height: radius * metaballScale)) let context = UIGraphicsGetCurrentContext() SKColor.whiteColor().setFill() CGContextFillEllipseInRect(context, CGRect(x: radius * ellipseOrigin, y: radius * ellipseOrigin, width: radius * 3, height: radius * 3)) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return SKTexture(CGImage: blur(image!)) } } func blur(image: UIImage) -> CGImage { let gaussianBlurFilter = CIFilter(name: "CIGaussianBlur") let inputImage = CIImage(CGImage: image.CGImage!) gaussianBlurFilter?.setValue(inputImage, forKey:kCIInputImageKey) gaussianBlurFilter?.setValue(5, forKey: kCIInputRadiusKey) let outputImage = gaussianBlurFilter?.outputImage let context = CIContext(options: nil) return context.createCGImage(outputImage!, fromRect: inputImage.extent) } 
+8
ios swift sprite-kit skspritenode skeffectnode
source share

No one has answered this question yet.

See related questions:

10
Metal crash when adding SKSpriteNode to SKEffectNode
3
Is the only SKSpriteNode w / PhysicalBody that is still on stage to use 70% CPU?
one
Scaling SkSpriteNodes with SpriteKit
one
SpriteKit SKSpriteNode speed when touching and holding
one
Applying CIFilter with SKEffectNode to SKSpriteNode
one
SpriteKit: the gap between SKSpriteNodes
0
SKEffectNode goes through children with a breakdown (iOS10 Spritekit)
0
SKMutableTexture for SKPhysicsBody. No collisions occur.
0
How to distinguish a node from a file other than GameScene?
-one
SKEffectNode, SpriteKit inverts color in Swift

All Articles