Search code examples
iossprite-kitskemitternode

Adding an SKEmitter node into my game


i get an error that reads "no visible @interface for viewcontroller declares the selector addChild" basicly im trying to add my skEmitter Node into my game.

-(void) didMoveToView:(SKView *) view{
   NSString *path = [[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"];
   SKEmitterNode *node = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
   node.position = CGPointMake(0, 100);
   [self addChild : node]

}

Solution

  • Try this:

    @implementation MyScene
    {
        SKEmitterNode *myParticle; // < add this
    }
    
    -(id)initWithSize:(CGSize)size {
        if (self = [super initWithSize:size])
        {
            myParticle = [[SKEmitterNode alloc] init]; // < add this
            [self startMyParticle]; // < add this
        }
    }
    
    -(void)startMyParticle // << add this entire method from start to finish
    {
        myParticle = [NSKeyedUnarchiver unarchiveObjectWithFile: [[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"]];
        myParticle.position = CGPointMake(200, 200); // < you can change these to the coordinates you want
        [self addChild: myParticle];
    }
    

    If you are really finding yourself getting interested in SpriteKit, then I suggest you expand your knowledge with some excellent tutorials. This will make your experience a lot less frustrating and put you on the road to becoming the next Angry Birds creator! Take a look at the tutorials on this site http://www.raywenderlich.com