w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Setting of physicsBody category bitmask values

I'd do neither of these.

I'd actually create an NS_OPTIONS typedef for it. Something like...

typedef NS_OPTIONS(uint32_t, MyPhysicsCategory)
{
    MyPhysicsCategoryAnt = 1 << 0,
    MyPhysicsCategoryFood = 1 << 1,
    MyPhysicsCategoryMouse = 1 << 2,
};

There is really no difference between what these do. They all just define ints and values of 1, 2, 4, 8, 16, etc...

The difference is in the readability.

By using the NS_OPTIONS way it tells me (and anyone else using my project) that you can use bitwise operations on them.

ant.physicsBody.contactTestBitMask = MyPhysicsCategoryMouse |
MyPhysicsCategoryFood;

I know that this means that the ant will be contacted tested against food and mice.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.