【发布时间】:2014-06-13 00:04:34
【问题描述】:
我是 SpriteKit 的新手,我正在尝试显示在 MyScene.m 的类中创建的对象(圆形)。这就是我所拥有的:
我在 CreateNewCircle.h 中写道:
#import <SpriteKit/SpriteKit.h>
@interface CreateNewCircle : SKScene
-(void) addNewCircle;
@end
并在 .m (CreateNewCircle.m) 中:
#import "CreateNewCircle.h"
@implementation CreateNewCircle
-(void) addNewCircle {
const CGSize size = self.frame.size;
const CGPoint center = CGPointMake(size.width * 0.5, size.height * 0.5);
CGRect box = CGRectMake(center.x - 40.0, center.y - 40.0, 80.0, 80.0);
SKShapeNode *shapeNode = [[SKShapeNode alloc] init];
shapeNode.path = [UIBezierPath bezierPathWithOvalInRect:box].CGPath;
shapeNode.fillColor = [SKColor redColor];
shapeNode.strokeColor = nil;
}
@end
现在我正在尝试从 MyScene.m 中调用此方法(在屏幕上显示一个圆圈):
MyScene.h:
#import <SpriteKit/SpriteKit.h>
@interface MyScene : SKScene
@end
MyScene.m:
#import "MyScene.h"
#import "CreateNewCircle.h"
@implementation MyScene {
}
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
self.backgroundColor = [SKColor colorWithWhite:255 alpha:1.0];
CreateNewCircle *circle1 = [[CreateNewCircle alloc] init];
[circle1 addNewCircle];
[self.scene addChild:circle1];
}
return self;
}
构建是好的,但是当我运行时,什么都没有出现。我尝试更改“addchild”行,例如:
[circle1 setName:@"circleOne"];
[self childNodeWithName:@"circleOne"];
但结果相同:空白屏幕。如果我直接在 MyScene.m 中编写相同的代码,就会出现圆圈,所以代码应该是正确的。有人可以帮我吗:-)?
谢谢。
【问题讨论】:
标签: ios class sprite-kit addchild