Duplicating a particle emitter effect in Sprite Kit

前端 未结 1 790
一生所求
一生所求 2021-02-04 01:15

I need to have a particle emitters effects to appear duplicated in 2 spots (For split screen purposes), I am wondering if anybody has come across a way of doing this. My goal i

相关标签:
1条回答
  • 2021-02-04 01:24

    This just works (I guess as intended), but I have no idea how much is performant or how it fits your needs and your current game. Anyways, maybe it can help you in some way. First, in your GameViewController...Split screen :)

    #import "GameViewController.h"
    #import "GameScene.h"
    
    @implementation GameViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        // Configure the view.
        SKView * leftSKView = (SKView *)self.leftScene;
        leftSKView.ignoresSiblingOrder = YES;
        leftSKView.showsFPS = YES;
        leftSKView.showsNodeCount = YES;
    
        SKView * rightSKView = (SKView *)self.rightScene;
        rightSKView.ignoresSiblingOrder = YES;
        rightSKView.showsFPS = YES;
        rightSKView.showsNodeCount = YES;
    
    
    
    
        // Create and configure the scene.
        GameScene *scene = [GameScene nodeWithFileNamed:@"GameScene"];
        scene.scaleMode = SKSceneScaleModeAspectFill;
    
        // Present the scene.
        [leftSKView presentScene:scene];
        [rightSKView presentScene:scene];
    
    }
    

    leftScene and rightScene are UIViews defined in a storyboard using autolayout to take half of a screen each. Also a class is changed to SKView (it was UIView). Pretty trivial...

    Then in your game scene just add an emitter which will be shared between these two views. Because only one emitter is used, particles emitting (how they move) will be mirrored. So in game scene, just add a particle:

    -(void)didMoveToView:(SKView *)view {
        /* Setup your scene here */
    
    
        SKEmitterNode *emitter =  [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"MyParticle" ofType:@"sks"]];
        emitter.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidX(self.frame));
        emitter.name = @"explosion";
        emitter.targetNode = self;
        [self addChild:emitter];
    }
    

    I know that you don't need all this code, but if this is what you want in some way, I will post it for completeness. And here is the result:

    0 讨论(0)
提交回复
热议问题