ios - SKSpriteNode ignoring physics deactivation -
i have node placed under screen , works platform. node touches node boolean set no. when define node skphysicsbody
properties collision node ignores affectedbygravity
property.
my code:
+ (void)addnewnodeto:(sknode *)parentnode { //correct image size skspritenode *desertbottom = [skspritenode node]; desertbottom = [[skspritenode alloc] initwithimagenamed:@"giraffe.png"]; desertbottom.position = cgpointmake(0, -200); desertbottom.zposition = 2; desertbottom.physicsbody.collisionbitmask = liontype; desertbottom.physicsbody.categorybitmask = terraintype; desertbottom.physicsbody.contacttestbitmask = liontype; desertbottom.zposition = 2; desertbottom.physicsbody = [skphysicsbody bodywithrectangleofsize:cgsizemake(desertbottom.size.width, desertbottom.size.height)]; desertbottom.physicsbody.dynamic = yes; desertbottom.physicsbody.affectedbygravity = no; [parentnode addchild:desertbottom]; }
my collision methods:
- (void)didbegincontact:(skphysicscontact *)contact { uint32_t collision = (contact.bodya.categorybitmask | contact.bodyb.categorybitmask); if (collision == (liontype | terraintype)) { self.lionnode.lionisjumping = no; nslog(@"%i", self.lionnode.lionisjumping); } } - (void)didendcontact:(skphysicscontact *)contact { uint32_t collision = (contact.bodya.categorybitmask | contact.bodyb.categorybitmask); if (collision == (liontype | terraintype)) { self.lionnode.lionisjumping = yes; nslog(@"%i", self.lionnode.lionisjumping); } }
a physics body has velocity. gravity changes velocity on time. if body traveling @ velocity due gravity, , disable gravity, continue move according current velocity no longer gain additional speed gravity.
my guess expect body stop when disabling gravity. if that's want can manually setting y component of velocity zero:
skphysicsbody* body = desertbottom.physicsbody; body.velocity = cgvectormake(body.velocity.x, 0.0);
Comments
Post a Comment