所以我在我正在测试的应用程序的 Skview 中设置了一个 skscene。我像这样设置背景颜色等。
SKView *skBG = [[SKView alloc] initWithFrame:self.view.bounds];
SKScene *scene = [SKScene sceneWithSize:self.view.bounds.size];
// Set the scale mode to scale to fit the window
scene.backgroundColor = [SKColor colorWithRed:0.12f green:0.2f blue:0.27f alpha:1.0f];
scene.scaleMode = SKSceneScaleModeAspectFit;
[skBG presentScene:scene];
NSString *myParticlePath = [[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"];
SKEmitterNode *snowParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
snowParticle.particlePosition = CGPointMake(160, 284);
scene addChild:snowParticle];
[self.view addSubview:skBG];
然后我想在已经呈现的场景中随机更改背景背景颜色。 我附上了一个标准计时器,它会在 5 秒后被调用,并在其中执行如下操作:
self.scene.backgroundColor = [SKColor colorWithRed:0.5f green:0.5f blue:0.5f alpha:1.0f];
但它不更新?我尝试用“[skView presentScene:scene];”表示场景但不起作用。
最佳答案
嗯,没有那么多要继续,但从你实际分享的内容来看,你可能实际上并没有显示 self.scene 属性。在您设置 SKView 的代码中:
SKScene *scene = [SKScene sceneWithSize:self.view.bounds.size];
但这与 .scene 属性不同(除非您在方法内的某处执行 self.scene = scene;
)。根据我们掌握的少量信息,我猜测您要么没有显示 self.scene 属性,要么正在用新的瞬间覆盖它。如果确实如此,那么它应该像改变你所做的一样简单:
SKView *skBG = [[SKView alloc] initWithFrame:self.view.bounds];
_scene = [SKScene sceneWithSize:self.view.bounds.size];
// Set the scale mode to scale to fit the window
self.scene.backgroundColor = [SKColor colorWithRed:0.12f green:0.2f blue:0.27f alpha:1.0f];
self.scene.scaleMode = SKSceneScaleModeAspectFit;
[skBG presentScene:self.scene];
NSString *myParticlePath = [[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"];
SKEmitterNode *snowParticle = [NSKeyedUnarchiver unarchiveObjectWithFile:myParticlePath];
snowParticle.particlePosition = CGPointMake(160, 284);
self.scene addChild:snowParticle];
[self.view addSubview:skBG];
关于ios - 使用计时器呈现 SKscene 后更改其背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21506438/