ios7 - SpriteNode not following cgpath -
i have problem new game sprite... "car" follows track on first lap on seems getting offset @ end of every lap. tell me doing wrong ?
- (void)createscenecontents{ self.backgroundcolor = [skcolor blackcolor]; self.scalemode = skscenescalemodeaspectfit; // creating car , track skspritenode *mycar = [self newcar]; mycar.position = [[self trackshape] position];; [self addchild:mycar]; skshapenode *track = [self trackshape]; track.position = cgpointmake(48, 40); [self addchild:track]; } - (skspritenode *)newcar{ // generates rectangle sprite node skspritenode *hull = [[skspritenode alloc] initwithcolor:[skcolor graycolor] size:cgsizemake(20,50)]; cgpathref pathref = [[self bpath] cgpath]; // car should follow track // ok on first lap skaction *hover = [skaction sequence:@[[skaction followpath:pathref duration:20.0], ]]; hull.physicsbody = [skphysicsbody bodywithrectangleofsize:hull.size]; hull.physicsbody.dynamic = no; [hull runaction: [skaction repeatactionforever:hover]]; return hull; } -(skshapenode *)trackshape{ skshapenode *newshape = [[skshapenode alloc] init]; newshape.position = cgpointmake(48, 40); newshape.path = [[self bpath] cgpath]; newshape.fillcolor = [skcolor clearcolor]; newshape.strokecolor = [skcolor bluecolor]; newshape.linewidth = 8; return newshape; }
this path... it's in same class.
-(uibezierpath *)bpath{ uibezierpath* bezierpath = [uibezierpath bezierpath]; [bezierpath movetopoint: cgpointmake(48, 40)]; [bezierpath addlinetopoint: cgpointmake(10.5, 147.5)]; [bezierpath addcurvetopoint: cgpointmake(131.5, 209.5) controlpoint1: cgpointmake(10.5, 147.5) controlpoint2: cgpointmake(45.01, 253.16)]; [bezierpath addcurvetopoint: cgpointmake(267.5, 209.5) controlpoint1: cgpointmake(217.99, 165.84) controlpoint2: cgpointmake(259.57, 194.46)]; [bezierpath addcurvetopoint: cgpointmake(283.5, 302.5) controlpoint1: cgpointmake(275.43, 224.54) controlpoint2: cgpointmake(325.48, 263.29)]; [bezierpath addcurvetopoint: cgpointmake(105.5, 327.5) controlpoint1: cgpointmake(241.52, 341.71) controlpoint2: cgpointmake(128.94, 352.5)]; [bezierpath addcurvetopoint: cgpointmake(10.5, 396.5) controlpoint1: cgpointmake(82.06, 302.5) controlpoint2: cgpointmake(-27.5, 333.95)]; [bezierpath addcurvetopoint: cgpointmake(239.5, 448.5) controlpoint1: cgpointmake(48.5, 459.05) controlpoint2: cgpointmake(195.5, 463.67)]; [bezierpath addcurvetopoint: cgpointmake(283.5, 40.5) controlpoint1: cgpointmake(399.5, 40.5) controlpoint2: cgpointmake(375.39, 205.99)]; [bezierpath addcurvetopoint: cgpointmake(153.5, 78.5) controlpoint1: cgpointmake(191.61, -124.99) controlpoint2: cgpointmake(153.5, 78.5)]; [bezierpath addlinetopoint: cgpointmake(48, 40)]; [bezierpath closepath]; return bezierpath; }
after while, results
i scrapped car method, , placed within this.
i had tweak position of track, seems work.
- (void)createscenecontents{ self.backgroundcolor = [skcolor blackcolor]; self.scalemode = skscenescalemodeaspectfit; skspritenode *hull = [[skspritenode alloc] initwithcolor:[skcolor graycolor] size:cgsizemake(20,50)]; cgpathref pathref = [[self bpath] cgpath]; skshapenode *track = [self trackshape]; //track.position = // scrap me.. set in track shape method [self addchild:track]; hull.physicsbody = [skphysicsbody bodywithrectangleofsize:hull.size]; hull.physicsbody.dynamic = no; hull.position = cgpointmake(48, 40); [self addchild:hull]; skaction *hover = [skaction followpath:pathref asoffset:no orienttopath:yes duration:5.0]; [hull runaction: [skaction repeatactionforever:hover]]; }
in trackshape method, set position 0,0
newshape.position = cgpointmake(0, 0);
Comments
Post a Comment