sprite kit - How to make SKSpritekit nodes bounce off each other -
i know how set physic attributes don't know code need create them bounce off each other realistically, balls on pool table. have didbegincontact method ready,
-(void)didbegincontact:(skphysicscontact*)contact { uint32_t collision = (contact.bodya.categorybitmask | contact.bodyb.categorybitmask); if (collision == (gearcategory | gear1category)) { [ } }
but have no thought code need in it, can math , vectoring skills help me out?
this easy task in sprite kit.
//add top of scene static const uint32_t spritecategory = 0x1 << 0; //declare when creating sprite sprite.physicsbody.categorybitmask = spritecategory; sprite.physicsbody.collisionbitmask = spritecategory;
what set sprite collide sprites given spritecategory categorybitmask. can have sprite set collide multiple different categorybitmasks using next code.
sprite.physicsbody.collisionbitmask = spritecategory|othercategory|anothercategory;
did begin contact used execute code when nodes touch. utilize contacttestbitmask property observe when items touch. collisionbitmask automatically handles collisions !!!
i have attached link has entire section devoted collision , contact.
http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners
sprite-kit
No comments:
Post a Comment