SKFieldNode magneticNode attracting forces

筅森魡賤 提交于 2019-11-29 09:36:55

问题


I am currently working with the iOS 8 SpriteKit API's and am having a hard time creating an attractive magnetic force with SKFieldNode. I can create an opposing magnetic force just fine, however I can't reverse the field. Heres what I have currently:

    touchField = [SKFieldNode magneticField];

    touchField.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:(self.frame.size.height/4 - 34)];

    touchField.physicsBody.charge = 3;

This particular field is supposed to be interactive with another SKSpriteNode.


回答1:


Electric and Magnetic fields are currently broken, as of iOS 8.1. They don't interact with the physics simulation at all.

What's probably causing your other node to move is that its physics body is inside the body you've attached to your field, which the simulation corrects by moving the nodes apart.

Also of note is that if magnetic fields were working properly, you don't need to add a physics body to it - the field node itself is intended to be enough to get the effect.

I've got an open bug report filed with Apple. Filing duplicates increases a bug's priority, so if you file one, mention that it's a duplicate of bug 18785194.

UPDATE: This bug still exists in iOS 8.3/Xcode 6.3 beta 2. I've received a request for more information on my bug report, so at least somebody at Apple is aware of it, but that was four beta versions ago.

UPDATE 2: This bug is partially resolved with iOS 9.0/Xcode 7.0 beta 2. Electric and magnetic fields now work, but custom fields are still broken.




回答2:


touchField.strength = -1;  

This line will reverse your field.



来源:https://stackoverflow.com/questions/24583736/skfieldnode-magneticnode-attracting-forces

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