![](/img/trans.png)
[英]How to add particle effects to an iOS App that is not a game using iOS 7 SpriteKit Particle?
[英]adding a SpriteKit particle to existing app
我已经向我的应用程序添加了SpriteKit粒子-skView已添加到现有图像视图(myImageView)。 一切正常,但无法将skScenne设置为清除颜色以在发射器后面显示myImage。 您可以更改颜色,但不能清除颜色? `
SKView *skView = [[SKView alloc] initWithFrame:CGRectMake(0.0, 0.0, 768, 1024)];
[myImageView addSubview:skView];
SKScene *skScene = [SKScene sceneWithSize:skView.frame.size];
skScene.scaleMode = SKSceneScaleModeAspectFill;
skScene.backgroundColor = [UIColor clearColor];
SKEmitterNode *emitter = [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"]];
generator.position = CGPointMake(400,0);
[skScene addChild:emitter];
[skView presentScene:skScene];
[self.view addSubview:myImageView];
不幸的是,您无法在iOS 7中使SKView透明。在iOS 8中,它可以通过以下方式工作:
skView.allowsTransparency = YES;
skScene.backgroundColor = [UIColor clearColor];
在iOS 7中,您可以添加一个大的spriteView,其背景大小与skView一样大,并将myImage设置为纹理。
由于性能原因,我建议您避免将SKScene的颜色设置为[UIColor clearColor](尽可能使用不透明视图)。 相反,您可以创建一个SKSpriteNode并将其添加到场景中作为背景...
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"image"];
background.size = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
// Bottom/left of your image
background.anchorPoint = CGPointZero;
background.position = CGPointZero;
// Make sure the background is behind other nodes in the scene
background.zPosition = -100;
[self addChild:background];
由于背景已添加到SKScene中,因此当您过渡到新场景时会自动将其删除/释放。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.