sprite kit - Updating physics body when animating with SKAction moveTo -
i have 'bar' moving , forth, have correctly gotten move sprite right left. seems physics body still in same place originally. can make contact 'bar' when has animated away.
does know how can fix this?
- (void)setupbars { leftbar = [barnode new]; leftbar.anchorpoint = cgpointmake(0, 0); leftbar.name = @"leftbar"; leftbar.size = cgsizemake(cgrectgetmidx(self.frame), 50); [leftbar setposition:cgpointmake(0, cgrectgetmidy(self.frame) + 275)]; leftbar.physicsbody = [skphysicsbody bodywithrectangleofsize:leftbar.size]; leftbar.physicsbody.dynamic = no; leftbar.physicsbody.contacttestbitmask = nodebitmask; [self addchild:leftbar]; rightbar = [barnode new]; rightbar.anchorpoint = cgpointmake(0, 0); rightbar.name = @"rightbar"; rightbar.size = cgsizemake(cgrectgetmidx(self.frame), 50); [rightbar setposition:cgpointmake(cgrectgetmidx(self.frame), cgrectgetmidy(self.frame) + 275)]; rightbar.physicsbody = [skphysicsbody bodywithrectangleofsize:rightbar.size]; rightbar.physicsbody.dynamic = no; rightbar.physicsbody.contacttestbitmask = nodebitmask; [self addchild:rightbar]; skaction *moveleftbar = [skaction moveto:cgpointmake(-160, leftbar.position.y) duration:1]; skaction *back = [skaction moveto:cgpointmake(0, leftbar.position.y) duration:1]; skaction *all = [skaction sequence:@[moveleftbar, back]]; skaction *repeat = [skaction repeatactionforever:all]; [leftbar runaction:repeat]; moveleftbar = [skaction moveto:cgpointmake(cgrectgetmidx(self.frame) + 160, rightbar.position.y) duration:1]; = [skaction moveto:cgpointmake(cgrectgetmidx(self.frame), rightbar.position.y) duration:1]; = [skaction sequence:@[moveleftbar, back]]; repeat = [skaction repeatactionforever:all]; [rightbar runaction:repeat]; }
you pretty answered own question. wanted there yourself. problem spritekit's physics bodies not react change in anchor points. based on 0.5,0.5 regardless of set node's anchor point to.
your options either modify node use default anchor point (0.5, 0.5) or use (skphysicsbody *)bodywithrectangleofsize:(cgsize)s center:(cgpoint)center
lets set center coordinates.
Comments
Post a Comment