objective c - creating convex SKPhisycsBodies -
i,m trying rectangle hole in new framework provided apple, problem default method bodywithpolygonfrompath not accept concave polygons, tried approach problem follows:
cgpathmovetopoint (path, null, self.size.width/4.0, self.size.height/4.0); cgpathaddlinetopoint(path, null, self.size.width/2.0, -self.size.height/4.0); cgpathaddlinetopoint(path, null, -self.size.width/2.0, -self.size.height/4.0); cgpathaddlinetopoint(path, null, -self.size.width/2.0, self.size.height/4.0); cgpathclosesubpath (path); self.physicsbody = [skphysicsbody bodywithpolygonfrompath:path]; self.physicsbody.affectedbygravity = yes; self.physicsbody.categorybitmask = solidcategory; self.physicsbody.dynamic = yes; [self addchild:shape1]; self.auxiliaryshapenode = [[skspritenode alloc] init]; cgpathmovetopoint (path_aux, null, 3*self.size.width/8.0, 0); cgpathaddlinetopoint(path_aux, null, self.size.width/2.0, 1.5*self.size.height/4.0); cgpathaddlinetopoint(path_aux, null, self.size.width/2.0, -self.size.height/4.0); cgpathclosesubpath (path_aux); self.auxiliaryshapenode.anchorpoint = cgpointmake(-3.0, 1.0/2.5); self.auxiliaryshapenode.physicsbody = [skphysicsbody bodywithpolygonfrompath:path_aux]; self.auxiliaryshapenode.physicsbody.dynamic = yes; self.auxiliaryshapenode.physicsbody.categorybitmask = solidcategory; [self addchild:self.auxiliaryshapenode]; [self.scene.physicsworld addjoint:[skphysicsjointfixed jointwithbodya:self.physicsbody bodyb:self.auxiliaryshapenode.physicsbody anchor:self.position]]; break;
where self custom sprite node created has sksprite node auxiliary body shape shape can made 2 convex polygons, creates shapes supposed to, when scene starts playing joint doesn't work supposed , moves little triangle way off started
i solved problem, did not find answer guess worked around
what realized point of bodyjoint obeyed x coordinate moved y coordinate 0, moved body 0,0 coordinate, , moved body again it´s previous position
cgpoint *prevposition = self.position; //positioning of node joint lands 0,0 self.position = cgpointmake(-3*self.size.width/8.0,0); cgpathmovetopoint (path, null, self.size.width/4.0, self.size.height/4.0); cgpathaddlinetopoint(path, null, self.size.width/2.0, -self.size.height/4.0); cgpathaddlinetopoint(path, null, -self.size.width/2.0, -self.size.height/4.0); cgpathaddlinetopoint(path, null, -self.size.width/2.0, self.size.height/4.0); cgpathclosesubpath (path); self.physicsbody = [skphysicsbody bodywithpolygonfrompath:path]; self.physicsbody.affectedbygravity = yes; self.physicsbody.categorybitmask = solidcategory; self.physicsbody.dynamic = yes; [self addchild:shape1]; self.auxiliaryshapenode = [[skspritenode alloc] init]; //now asssign frame, position not matter determined joint self.auxiliaryshapenode.frame = cgrectmake(0,0,sel.size.width/8.0,self.height/2); self.auxiliaryshapenode.anchor = cgpointmake(0,0.5); cgpathmovetopoint (path_aux, null, 0,0); cgpathaddlinetopoint(path_aux, null, self.auxiliaryshapenode.size.width, self.auxiliaryshapenode.size.width/2.0); cgpathaddlinetopoint(path_aux, null, self.auxiliaryshapenode.size.width, -self.auxiliaryshapenode.size.width/2.0); cgpathclosesubpath (path_aux); self.auxiliaryshapenode.physicsbody = [skphysicsbody bodywithpolygonfrompath:path_aux]; self.auxiliaryshapenode.physicsbody.dynamic = yes; self.auxiliaryshapenode.physicsbody.categorybitmask = solidcategory; [self addchild:self.auxiliaryshapenode]; [self.scene.physicsworld addjoint:[skphysicsjointfixed jointwithbodya:self.physicsbody bodyb:self.auxiliaryshapenode.physicsbody anchor:cgpointzero]]; self.position=prevposition;
so, managed "make work" way, hope it´s useful someone
Comments
Post a Comment