SpriteKit and particle collision

佐手、 提交于 2019-12-11 04:05:59

问题


I have a particle emitter and I would like to detect it when the particles collide some physics bodies. Is there a native way to do that in the SpriteKit API or do I need "to cheat" ?


回答1:


Individual particles can not collide. Not with physics, not any other way. You do not even get any information about an individual particle - you can't access it's position, rotation, velocity .. nothing.

If you wanted to "cheat" you'd have to emulate the particle emitter using sprites, and animate the sprites with actions or manually. However keep in mind that this is much less efficient than a particle emitter.

In addition, if we're talking "particles" which often means dozens or even hundreds of them on screen, the amount of physics processing and collision detection quickly becomes prohibitively expensive if you were to model them using sprites with physics bodies attached. Do a performance test before you go down this path.




回答2:


Particles do not have physics bodies, so they don't collide with Sprite Kit's physics engine




回答3:


You can set the physics body of the particle emitter the same way you set it for any sprite node. Then you can set the category bit mask property and the contact test bit mask. The method didBeganContact can detect the collision afterwards.




回答4:


didBegan contact is called whenever two bodies contact each other . Here is the apple reference link for how this method works:

Click [here](https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKPhysicsContactDelegate_Ref/Reference/Reference.html#//apple_ref/occ/intfm/SKPhysicsContactDelegate/didBeginContact:"Apple iOS developer library")!



来源:https://stackoverflow.com/questions/24402853/spritekit-and-particle-collision

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!