Question

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]

}
Was it helpful?

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

OTHER TIPS

Add it to MyScene.m within it's own method and NOT in the ViewDidLoad (view controller)

here is a link to check the requirements: https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKEmitterNode_Ref/Reference/Reference.html

also make sure you have Sprite kit frame Work in you project or start with the sprite kit template provided by apple.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top