Cocos2d 中粒子的碰撞检测
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于警告,请确保您的发射器是由您的子类(而不是常规的 CCParticleSystemQuad)制成的,并且您的 getter 方法是在接口(.h 文件)中声明并在实现(.m 文件)中定义的。
查看 API,我没有看到
setParticlePos:newPosition:
的方法,但有一些看起来相似的东西:-(void) updateQuadWithParticle:(tCCParticle*)article newPosition:(CGPoint)pos;
我没有使用过它,但看一下源代码表明它可以满足您的需要。
所以也许可以尝试
[emitter updateQuadWithParticle:article newPosition:newPos];
希望对您有所帮助。
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.