0

So this is my situation.

I have emitters spawning from the top of the screen and travelling to the bottom of the screen and I'm trying to get a png image to follow them (for hit detection purposes)

The problem is that I need to have the PNG images live update to track the skemitternode and because I am generating several instances of the emitter node I can't make them global variables (need a new localized set for n instances)

So the solution I have come up with is to have a while loop that continues to update the PNG to the emitter nodes coordinates. The conditions of the loop would be to continue while the number of particles is less than 500 (the particle lifetime I have set).

I am having trouble getting the png image to stay with the skemitter node. It always goes above it or looses tracking.

Currently I am using:

while (particle < 5000) {
    enemySmoke.position = Enemy.position
    particle++
}

Where enemySmoke is the SKEmitter node travelling down the Y axis

var action = SKAction.moveToY(SH-SH, duration: 10 - duration)
// Basically moving to bottom of screen faster with each spawn as I have 
// duration variable incrementing.

enemySmoke.runAction(SKAction.repeatActionForever(action))
Enemy.runAction(SKAction.repeatActionForever(action))

How can I get the emitter and the png to remain on each other?

Reg Edit
  • 6,719
  • 1
  • 35
  • 46

1 Answers1

0

To have an SKEmitterNode 'follow' an SKSpriteNode, by far the simplest solution is to have the emitter as a child of your SKSpriteNode and only move the SKSpriteNode. For example:

sprite.addChild(emitter)

At the moment the particles emitted are going to be added to the the SKSpriteNode. This is not an idea behaviour since the particles will move with the SKSpriteNode. To fix this you should set the targetNode of the SKEmitterNode to the be SKScene:

emitter.targetNode = self // Assuming self is the SKScene.
ABakerSmith
  • 22,759
  • 9
  • 68
  • 78
  • For some reason it still is not following. This is the code I'm using – James Callyway Jun 04 '15 at 21:00
  • self.addChild(Enemy) Enemy.addChild(enemySmoke) enemySmoke.targetNode = EnemyNode – James Callyway Jun 04 '15 at 21:01
  • where Enemy is the SKSprite and enemySmoke is the emitter. EnemyNode being the node created for the enemy SKSprite – James Callyway Jun 04 '15 at 21:01
  • Also for some reason the movements are extremely choppy. Any solution you could propose ? – James Callyway Jun 04 '15 at 21:07
  • Humm, I'm not sure why the emitter isn't moving with the sprite? What is happening? Is the sprite moving and the emitter isn't? Regarding the choppy movement, what's your fps like? You may have too many particles onscreen at once... – ABakerSmith Jun 04 '15 at 21:24
  • It is moving with the sprite now but the movement is extremely choppy. The FPS is fine >60 – James Callyway Jun 04 '15 at 22:43
  • What are you using to move the `SKSpriteNode`? Using the method I've detailed above you should only be using an `SKAction` run by the `SKSpriteNode`. – ABakerSmith Jun 04 '15 at 22:54
  • It seems to work amazing when collision detection is not engaged. When I use collision detection with bitmasks it is extremely choppy. Could you guide me to the right way to implement it without this choppiness? – James Callyway Jun 04 '15 at 23:30
  • I fixed it. Gravity was set to true by default pushing against the movement I was trying to do – James Callyway Jun 04 '15 at 23:43
  • Ahh, something to look out for in the future :) I'm glad you got it sorted though. Good luck with your project! – ABakerSmith Jun 04 '15 at 23:44