Cocos2d 中粒子的碰撞检测

发布于 2024-11-17 22:36:16 字数 887 浏览 4 评论 0原文

我正在使用 CCParticleSystemQuad 来创建粒子效果。现在我想测试与 Cocos2d 场景中的 CGRect 的碰撞。我列出了与此类似的另一个主题,并且更接近了一些,但我仍然没有完整的解决方案,因此我重新列出了一个略有不同的主题标题。

我有一半的解决方案。我可以获得每个粒子的位置并可以测试碰撞,现在我想设置每个粒子碰撞时的位置。 我目前正在对 CCParticleSystemQuad 进行子类化,然后添加我自己的 getter,如下所示:

-(tCCParticle*)getQuadParticle:(int)quadIndex
{
    return &particles[quadIndex];
}

然后在我的 Cocos2d 场景中我可以获得粒子和位置:

tCCParticle *particle = [emitter getQuadParticle:i];
CGPoint pos = particle->pos;

这可以工作,但警告 CCParticleSystemQuad 可能不会响应 getQuadParticle。这是一个问题,但我现在想做的是以类似的方式设置场景中的位置,例如:

[emitter setParticlePos:i newPosition:newPos];

但是我不确定如何制作一个在我的场景中执行此操作的设置器。如果可能的话,我不想在粒子子类内进行碰撞检测。

我开始了另一个类似性质的主题,称为“如何在 Cocos2d (iphone) 中获取粒子位置”,我被告知要覆盖“更新”方法或“updateQuadWithParticle”方法,但我不确定如何准确地解决这个问题。

如果有人可以向我展示如何执行此操作的示例,我将不胜感激。

I am using CCParticleSystemQuad to create a particle effect. Now I would like to test for collisions with a CGRect from my Cocos2d scene. I listed another subject similar to this one and got a little closer however I still do not have the full solution so I have re-listed with a slightly different subject title.

I have half of the solution. I can get the position of each particle and can test for collisions, now I would like to set the positions of each when they collide.
I am currently subclassing the CCParticleSystemQuad and then adding my own getter like so:

-(tCCParticle*)getQuadParticle:(int)quadIndex
{
    return &particles[quadIndex];
}

Then in my Cocos2d scene I can get the particle and the position:

tCCParticle *particle = [emitter getQuadParticle:i];
CGPoint pos = particle->pos;

This works but warns that CCParticleSystemQuad may not respond to getQuadParticle. Which is a concern, but what I would like to do now is set the position from the scene in a similar fashion such as:

[emitter setParticlePos:i newPosition:newPos];

However I am not sure how to make a setter that does this that works from my scene. I don't want to do collision detion inside the particle subclass if possible.

I started another topic of similar nature called "How to get particle position in Cocos2d (iphone)" and I was told to overide the "update" method or the "updateQuadWithParticle" method but I am unsure how to go about this exactly.

If someone could show me an example of how to do this I would be most grateful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱本泡沫多脆弱 2024-11-24 22:36:16

这有效,但警告 CCParticleSystemQuad 可能不会响应
获取QuadParticle。

对于警告,请确保您的发射器是由您的子类(而不是常规的 CCParticleSystemQuad)制成的,并且您的 getter 方法是在接口(.h 文件)中声明并在实现(.m 文件)中定义的。

查看 API,我没有看到setParticlePos:newPosition: 的方法,但有一些看起来相似的东西:-(void) updateQuadWithParticle:(tC​​CParticle*)article newPosition:(CGPoint)pos;

我没有使用过它,但看一下源代码表明它可以满足您的需要。

所以也许可以尝试
[emitter updateQuadWithParticle:article newPosition:newPos];

希望对您有所帮助。

This works but warns that CCParticleSystemQuad may not respond to
getQuadParticle.

For the warning, make sure your emitter is made from your subclass (and not a regular CCParticleSystemQuad), and that your getter method is declared in the interface (.h file) and defined in the implementation (.m file).

Looking at the API, I don't see a method for setParticlePos:newPosition: but there is something that looks similar: -(void) updateQuadWithParticle:(tCCParticle*)particle newPosition:(CGPoint)pos;

I have not used it, but a glance at the source suggests it does what you need.

So maybe try
[emitter updateQuadWithParticle:particle newPosition:newPos];

Hope that's helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文