How to resize SKEmitterNode?

I just wanted to do something that for me seems very simple, which makes the emitter look at the whole background of the presentation ... then I would like the view to have a Fill aspect, scale, etc., which allows the emitter to look right no matter what i do ...

I do not want to just scale the emitter. I want the objects to remain in the correct size, but I want the emitter area to change ... think of it as a β€œcanvas size” (no resizing) in Photoshop.

I would use this effect, for example, to add snow or rain to the whole scene or to create a snow globe sprite ...

The thing, maybe I'm just not looking in the right place, but it seems that any size properties on SKEmitterNode are read only ... what am I doing wrong?

here is some code where the resulting emitter is a small rectangle in the middle of the view.

override func viewDidLoad() { super.viewDidLoad() if let scene = GameScene(fileNamed:"GameScene") { // Configure the view. let skView = self.view as! SKView skView.showsFPS = true skView.showsNodeCount = true if let emitter = SKEmitterNode(fileNamed: "Bokeh") { emitter.position = view.center scene.addChild(emitter) } /* Sprite Kit applies additional optimizations to improve rendering performance */ skView.ignoresSiblingOrder = true /* Set the scale mode to scale to fit the window */ scene.scaleMode = .AspectFill skView.presentScene(scene) } } 

I need to clarify a little more. For snow, I would like particles to create an instance before they entered the scene, and then fall through the stage and die only after they left the scene, and not randomly appear throughout the scene, and then continued to fall .. I would like the snow to occupy all the boundaries of the scene.

+5
source share
1 answer

What you are looking for is called particlePositionRange :

The range of acceptable random values ​​for the position of the particles.

You can change it as follows:

  emitterNode.particlePositionRange = CGVector(dx: dx, dy: dy) 

dx should be the width of your emitter, and dy should be the height. This may be the size of the scene (note that the default size of the scene is 1024x768, unless otherwise specified).

The same thing you can do using the particle editor by changing the values ​​in the "Position Range" section:

range of positions

+6
source

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


All Articles