一关面、粒子效果:SKEmitterNode
-
雪花效果 <轉(zhuǎn)換出來的gif有點模糊嗯>
-
煙花效果<轉(zhuǎn)換出來的gif有點模糊嗯>
火焰效果蜕青、冒煙效果瘟栖、下雨效果等等
-
自定義效果
創(chuàng)建粒子效果步驟<以雪花舉例>
-
創(chuàng)建.sks文件 : File - file - SpriteKit Particle file , 選擇對應粒子效果
-
更改Main.storyboard 文件中view對應的父視圖層級結構
-
創(chuàng)建Scene類 : File - file - SpriteKit Scene ,
@property(nonatomic,strong)SKEmitterNode* emitter; - (void)didMoveToView:(SKView *)view { NSString*burstPath =[[NSBundle mainBundle] pathForResource:@"snow"ofType:@"sks"]; self.emitter = [NSKeyedUnarchiver unarchiveObjectWithFile:burstPath]; _emitter.position=CGPointMake(self.size.width/2,self.size.height/2-100); [self addChild:_emitter]; }
5.如果想滑動、點擊等也實現(xiàn)對應效果的話蜡豹,實現(xiàn)下列代碼
- (void)touchDownAtPoint:(CGPoint)pos {
SKEmitterNode *n = [_emitter copy];
n.position = pos;
// n.strokeColor = [SKColor greenColor];
[self addChild:n];
}
//- (void)touchMovedToPoint:(CGPoint)pos {
// SKEmitterNode *n = [_emitter copy];
// n.position = pos;
//// n.strokeColor = [SKColor blueColor];
// [self addChild:n];
//}
- (void)touchUpAtPoint:(CGPoint)pos {
SKEmitterNode *n = [_emitter copy];
n.position = pos;
// n.strokeColor = [SKColor blueColor];
[self addChild:n];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// Run 'Pulse' action from 'Actions.sks'
for (UITouch *t in touches) {[self touchDownAtPoint:[t locationInNode:self]];}
}
//- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
// for (UITouch *t in touches) {[self touchMovedToPoint:[t locationInNode:self]];}
//}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *t in touches) {[self touchUpAtPoint:[t locationInNode:self]];}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *t in touches) {[self touchUpAtPoint:[t locationInNode:self]];}
}
-
加載效果
GameScene *scene = (GameScene *)[SKScene nodeWithFileNamed:@"GameScene"]; // scene.size = CGSizeMake(KScreenWidth, KScreenHeight); // Set the scale mode to scale to fit the window scene.scaleMode = SKSceneScaleModeAspectFill; SKView *skView = (SKView *)self.view; skView.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight); // Present the scene [skView presentScene:scene]; skView.showsFPS = YES; skView.showsNodeCount = YES;
二麸粮、拖曳效果:SKShapeNode
更改Main.storyboard 文件中view對應的父視圖層級結構
-
創(chuàng)建Scene類 : File - file - SpriteKit Scene
@property(nonatomic,strong) SKShapeNode * spinnyNode; - (void)didMoveToView:(SKView *)view{ CGFloat w = (self.size.width + self.size.height) * 0.05; // Create shape node to use during mouse interaction _spinnyNode = [SKShapeNode shapeNodeWithRectOfSize:CGSizeMake(w, w) cornerRadius:w * 0.3]; _spinnyNode.lineWidth = 2.5; [_spinnyNode runAction:[SKAction repeatActionForever:[SKAction rotateByAngle:M_PI duration:1]]]; [_spinnyNode runAction:[SKAction sequence:@[ [SKAction waitForDuration:0.5], [SKAction fadeOutWithDuration:0.5], [SKAction removeFromParent], ]]]; }
-
拖動等代碼實現(xiàn)
- (void)touchDownAtPoint:(CGPoint)pos { SKShapeNode *n = [_spinnyNode copy]; n.position = pos; n.strokeColor = [SKColor greenColor]; [self addChild:n]; } - (void)touchMovedToPoint:(CGPoint)pos { SKShapeNode *n = [_spinnyNode copy]; n.position = pos; n.strokeColor = [SKColor blueColor]; [self addChild:n]; } - (void)touchUpAtPoint:(CGPoint)pos { SKShapeNode *n = [_spinnyNode copy]; n.position = pos; n.strokeColor = [SKColor redColor]; [self addChild:n]; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // Run 'Pulse' action from 'Actions.sks' for (UITouch *t in touches) {[self touchDownAtPoint:[t locationInNode:self]];} } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ for (UITouch *t in touches) {[self touchMovedToPoint:[t locationInNode:self]];} } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *t in touches) {[self touchUpAtPoint:[t locationInNode:self]];} } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *t in touches) {[self touchUpAtPoint:[t locationInNode:self]];} }