I need to simulate a fan. In Box2D, I do this through the use of a sensor body. I haven't discovered anything in SK that works similarly. I could be wrong. Any suggestions? thanks a lot!
If what you're trying to do is create a body that will result in contact notifications but not collisions, you can use the categoryBitMask
, collisionBitMask
, and contactTestBitMask
properties:
Select a bit to represent the sensor category:
#define kSensorCategoryBit (0) // Pick your own bit here
#define kSensorCategory (1 << (kSensorCategoryBit))
Set the properties for the sensor body:
sensorBody.categoryBitMask = kSensorCategory; // Set sensor category bit
sensorBody.collisionBitMask = 0x00000000; // Prevent all collisions
sensorBody.contactTestBitMask = 0x00000000; // Prevent contacts between sensors
Set the properties for the other bodies that you want notifications for:
otherBody.contactTestBitMask |= kSensorCategory; // Set sensor category bit
Set the physics world's contact delegate:
scene.physicsWorld.contactDelegate = contactDelegate;
Implement the contact delegate methods for the contactDelegate
object:
- (void)didBeginContact:(SKPhysicsContact *)contact
- (void)didEndContact:(SKPhysicsContact *)contact
See Apple's documentation on SKPhysicsContact
for more information. Hope that helps...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With