Im creating an spark affect for a bomb that rotates and scrolls across the screen using SKEmitterNode. I've come to a sticking point as i can't correctly position the spark effect. I can get the SKEmitterNode and spriteNode to move across the screen together with the spark affect positioned in the centre of the bomb while the bomb rotates. The effect i wish to achieve is the spark positioned correctly at the end of the wick on the bomb while the bomb rotates.
The first piece of code is from myScene:
MCBomb *_multiUp = [MCBomb spriteNodeWithImageNamed:@"MultiShotPowerUp"];
[_mainLayer addChild:_multiUp];
// Create spark.
NSString *bombSparkPath = [[NSBundle mainBundle] pathForResource:@"BombSpark" ofType:@"sks"];
SKEmitterNode *_bombSpark = [NSKeyedUnarchiver unarchiveObjectWithFile:bombSparkPath];
_bombSpark.targetNode = _mainLayer;
[_mainLayer addChild:_bombSpark];
_multiUp.spark = _bombSpark;
The next two pieces of code are from the class .m
-(void)updateSpark {
if (self.spark) {
self.spark.position = self.position;
}
and .h
@interface MCBomb : SKSpriteNode
@property (nonatomic) SKEmitterNode *spark;
-(void)updateSpark;
As soon as i add CGPointMake into the mix e.g.
self.spark.position = CGPointMake(0.9, 0.9);
when called the spriteNode floats across the screen and the SKEmitterNode appear bottom left corner static.
Or if i do something like:
self.spark.position = CGPointMake (self.size.width +50 , self.size.height + 400);
The SKEmitterNode is static in its new position and the spriteNode floats across the screen. Or if i do this:
self.spark.position = CGPointMake (self.size.width +50 , self.size.height + 400);
self.position = self.spark.position;
I get both spriteNode and EmitterNode static in there new position.
As you can see, In my frustration i'm clutching at straws! The positioning is extreme just for affect, I'm still learning and could do with some advice on how to get the correct affect.
Below is the complete class, please see new comment:
-(void)spawnMultiShotPowerUp {
// Setting up Texture Atlas.
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"Parts"];
MCBomb *_multiUp = [MCBomb spriteNodeWithImageNamed:@"MultiShotPowerUp"];
_multiUp.name = @"multiUp";
_multiUp.position = CGPointMake(-_multiUp.size.width, randomInRange(150, self.size.height -100));
_multiUp.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:16.0];
_multiUp.physicsBody.categoryBitMask = mCMultiUpCategory;
_multiUp.physicsBody.collisionBitMask = 0;
_multiUp.physicsBody.velocity = CGVectorMake(10, randomInRange(-40, 40));
_multiUp.physicsBody.angularVelocity = M_PI;
_multiUp.physicsBody.linearDamping = 0.0;
_multiUp.physicsBody.angularDamping = 0.0;
[_mainLayer addChild:_multiUp];
// Create spark.
NSString *bombSparkPath = [[NSBundle mainBundle] pathForResource:@"BombSpark" ofType:@"sks"];
SKEmitterNode *_bombSpark = [NSKeyedUnarchiver unarchiveObjectWithFile:bombSparkPath];
_bombSpark.targetNode = _mainLayer;
_bombSpark.position = CGPointMake(20, 0);
_multiUp.spark = _bombSpark;
[_multiUp addChild:_bombSpark];
}