在 Sprite Kit 中复制粒子发射器效果 [英] Duplicating a particle emitter effect in Sprite Kit

查看:26
本文介绍了在 Sprite Kit 中复制粒子发射器效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个粒子发射器效果在 2 个点上重复出现(出于分屏目的),我想知道是否有人遇到过这样做的方法.我的目标是让它在 iOS 10 上运行.这是我到目前为止所尝试的.

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 is to have this running on iOS 10. Here is what I have tried so far.

  1. targetNode 分配给 SKNode,然后每帧复制 SKNode:targetNode 在 iOS 10 中不起作用给我.
  2. 将粒子发射器分配给 SKNode,并使用 view.textureFromNode 制作纹理以复制每一帧:需要 1/120 帧,对于我.
  3. 将自定义操作分配给将节点复制到另一个 SKNode 的粒子节点:操作将不会在 iOS 10 上运行
  4. 复制现有的粒子节点,希望种子不是随机的:种子是随机的
  5. 尝试在更新时复制粒子发射器:粒子仅在原点生成
  6. 尝试过 SKReferenceNode :只是发射器的副本,可自行运行
  1. Assigning targetNode to an SKNode and then copying SKNode every frame: targetNode does not work in iOS 10 for me.
  2. Assigning the particle emitter to an SKNode, and using view.textureFromNode to make a texture to copy every frame : takes 1/120th of a frame, too slow for me.
  3. Assigning a custom action to a particle node that duplicates the node into another SKNode : Actions will not run on iOS 10
  4. Copying the existing particle node in hopes that the seed is not random : The seed is random
  5. Tried copying the particle emitter on update : Particle just spawns at origin
  6. Tried SKReferenceNode : Just a copy of the emitter, runs on its own

真正发射我剩下的唯一选择是编写我自己的粒子发射器,我试图避免这种情况,所以我想知道是否有其他人遇到这个问题并且知道实现预期效果的解决方案.

The only option I am left for true emitting is writing my own particle emitter, which I am trying to avoid, so I am wondering if anybody else had this problem and knew of a solution to achieve desired effect.

我可以做的另一件事是预渲染发射器,但如果我走这条路,这将占用大量纹理内存.

The other thing I could do is prerendering the emitters, but this will take up a lot of texture memory if I go this route.

为了帮助可视化,我画了一张图片,白色边框显示了分屏发生的位置.黑色边框显示场景环绕发生的位置.

To help visualize, I drew a picture, The white border shows where the Split Screen happens. The black border shows where the scene wrapping happens.

截至目前,玩家 1 和玩家 2 都在原始场景中.

As of right now, both Player 1 and Player 2 are on the original scene.

玩家 2 向右走,即将击中世界环绕以将他移动到世界的左侧,但他还没有击中它.所以我需要有一个正在发生的场景的副本,以便它在视觉上看起来像一个场景.由于玩家 1 仍在原始场景中,因此原始发射器需要保持原位.玩家 2 将不得不在副本中看到相同的图像,否则一旦他通过该边界,就会发生故障"效果,并且包装的错觉现在消失了.

Player 2 is walking right and is about to hit a world wrap to move him to the left hand side of the world, but he has not hit it yet. So I need to have a copy of the scene happening so that it visually looks like one scene. Since player 1 is still on the original scene, the original emitter needs to stay in place. Player 2 is going to have to see the same image happening in the copy, otherwise once he passes that border, a "glitchy" effect will happen, and the illusion of wrapping is now gone.

最终结果:

我们刚刚说了 F%%% 它,玩家 1 和玩家 2 将查看不同的发射器节点,我们将在需要时将发射器附加到每个玩家的相机.

We just said F%%% it, Player 1 and Player 2 will be looking at different emitter nodes, we will just attach the emitters to each players camera when needed.

推荐答案

这只是工作(我猜是预期的),但我不知道有多少性能或它如何满足您的需求和您当前的游戏.无论如何,也许它可以以某种方式帮助你.首先,在你的 GameViewController...分屏:)

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];

}

leftScenerightScene 是在故事板中定义的 UIView,使用自动布局来分别占据屏幕的一半.还有一个类更改为 SKView(它是 UIView).相当琐碎...

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:

这篇关于在 Sprite Kit 中复制粒子发射器效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆