i learning sprite kit , dealing collisions of objects. got snippet of code apple docs , trying figure out &bitwise operator doing. first time using bitwise. know && logic operator evaluates left , right side true or false.
checking left , right make sure both not equal 0?
code:
static const uint32_t landercatagory = 0x1; static const uint32_t rockcatagory = 0x1 << 1; static const uint32_t photoncatagory = 0x1 << 2; static const uint32_t edgecatagory = 0x1 << 3; -(void)didbegincontact:(skphysicscontact *)contact{ skphysicsbody *firstbody; skphysicsbody *secondbody; if (firstbody.categorybitmask < secondbody.categorybitmask) { firstbody = contact.bodya; secondbody = contact.bodyb; } else{ firstbody = contact.bodyb; secondbody = contact.bodya; } [b] if ((firstbody.categorybitmask & photoncatagory) != 0) [/b]{ nslog(@"big bada boom"); } nslog(@"contact"); }
it bitwise , operation.
0 , 0 = 0
0 , 1 = 0
1 , 0 = 0
1 , 1 = 1
Forums Macs Mac Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
Comments
Post a Comment