我正在尝试修改我已经添加到SKShapeNode中的SKNode。
这是我将SKNode添加到屏幕并将SKShapeNode附加到屏幕上的代码。现在我正在尝试修改特定SKShapeNode的颜色,但我不知道该如何做。有什么建议吗?
SKNode *dot = [SKNode node];
SKShapeNode *circle = [SKShapeNode node];
circle.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 20, 20)].CGPath;
circle.fillColor = [UIColor blueColor];
circle.strokeColor = [UIColor blueColor];
circle.glowWidth = 5;
[dot addChild:circle];
[self addChild:dot];发布于 2013-11-24 19:54:04
试着移除所有的孩子和读新的孩子
[dot removeAllChildren];
[dot addChild:circle];发布于 2013-11-25 06:22:54
使SKShapeNode成为SKScene的属性
@interface YourScene()
@property SKShapeNode *circle;
@end将创建圆圈的代码更改为:
self.circle = [SKShapeNode node];
self.circle.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 20, 20)].CGPath;
self.circle.fillColor = [UIColor blueColor];
self.circle.strokeColor = [UIColor blueColor];
self.circle.glowWidth = 5;
[dot addChild:self.circle];现在您可以访问场景中任何位置的circle节点:
- (void)changeColor {
self.circle.fillColor = [SKColor redColor];
}另一种选择是给节点一个名称:
SKShapeNode *circle = [SKShapeNode node];
.....
circle = @"circle";并按名称访问该节点。
- (void)changeColor {
// Assuming the dot node is a child node of the scene
SKShapeNode *circle = (SKShapeNode*)[self.scene childNodeWithName:@"/circle"];
circle.fillColor = [SKColor redColor];
}https://stackoverflow.com/questions/20179937
复制相似问题