2

我收到一个错误,上面写着“viewcontroller 没有可见的@interface 声明选择器 addChild”基本上是我试图将我的 skEmitter 节点添加到我的游戏中。

-(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]

}
4

2 回答 2

1

试试这个:

@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];
}

如果你真的发现自己对 SpriteKit 感兴趣,那么我建议你通过一些优秀的教程来扩展你的知识。这将使您的体验不那么令人沮丧,并让您踏上成为下一个愤怒的小鸟创造者的道路!看看这个网站上的教程http://www.raywenderlich.com

于 2014-04-10T23:28:29.367 回答
0

将其添加到 MyScene.m 在它自己的方法中,而不是在 ViewDidLoad(视图控制器)中

这是检查要求的链接:https ://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKEmitterNode_Ref/Reference/Reference.html

还要确保你有 Sprite kit 框架在你的项目中工作或从苹果提供的 sprite kit 模板开始。

于 2014-04-10T17:44:36.083 回答