ios - How to make several sprite nodes each with a special path to follow -


i trying make game flight control there x amount of cars , each 1 has own path follow. idea make car class of subtype sknode , have cgmutablepathref instance variable each object. can make cgmutablepathref touchsbegins, touchsmoved, , touchesended , figured have each object follow specific path skaction followpath. approach? if not how it? have far vehicle class:

vehicle.h

@interface vehicle: sknode  @property (nonatomic, assign) cgmutablepathref pathtofollow; @property (nonatomic) cgfloat speed; @property (nonatomic) int direction;  - (instancetype)initwith:(cgmutablepathref)pathpassed;  @end 

vehicle.m

@implementation vehicle : sknode  @synthesize pathtofollow; @synthesize speed; @synthesize direction;   - (id)init {     self = [super init];     if (self) {         skspritenode *vehicle = [skspritenode spritenodewithimagenamed:@"spaceship"];         [self addchild:vehicle];         [self setdirection:4];         [vehicle setname:@"car"];         [self setscale:.5];     }     return self; } - (id)initwith:(cgmutablepathref)pathpassed {      self = [super init];     if (self) {         skspritenode *vehicle = [skspritenode spritenodewithimagenamed:@"spaceship"];         [self addchild:vehicle];         [self setpathtofollow:pathpassed];         [self setdirection:4];         [vehicle setname:@"car"];         [self setscale:.1];     }      return self; }  @end 

edit: adding gamescene in hopes help. having problem implementation vehicle object following path after jumps coordinates of first point + nodes position on scene (ex: position = (200, 200), first point = (123, 456) go (323, 656) follow path). draws line want follows way on coordinate. again help!

gamescene.m

-(void)didmovetoview:(skview *)view {     _car = [[vehicle new] init]; // init vehicle object set position     [_car setposition:cgpointmake(self.scene.size.width/2, self.scene.size.height/2)];     [self addchild_car]; // add child scene }  -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event {      // node touched     uitouch* touch = [touches anyobject];     cgpoint positioninscene = [touch locationinnode:self];     _nodetouchedfirst = [self nodeatpoint:positioninscene];      if ([_nodetouchedfirst.name isequaltostring:@"car"]) {         if (linenode != null) { // remove previous path             [linenode removefromparent];             [cgpathrelease(pathtodraw);         }          //start new path , display on screen         pathtodraw = cgpathcreatemutable();         cgpathmovetopoint(pathtodraw, null, positioninscene.x, positioninscene.y);         linenode = [skshapenode];         linenode.path = pathtodraw;         linenode.strokecolor = [skcolor redcolor];         [self addchild:linenode];       } } // touchesbegan  - (void)touchesmoved:(nsset*)touches withevent:(uievent*)event {     if ([_nodetouchedfirst.name isequaltostring:@"car"]) {         uitouch* touch = [touches anyobject];         cgpoint positioninscene = [touch locationinnode:self];          cgpathaddlinetopoint(pathtodraw, null, positioninscene.x, positioninscene.y);         linenode.path = pathtodraw;     } } // touchesmoved  - (void)touchesended:(nsset *)touches withevent:(uievent *)event {     if ([_nodetouchedfirst.name isequaltostring:@"car"]) {         skaction *followpath = [skaction followpath:pathtodraw asoffset:yes orienttopath:no duration:2];         [_nodetouchedfirst runaction:followpath];         linenode.strokecolor = [skcolor graycolor];     }  } 

some observations may or may not help:

  • you're setting position of _car , adding scene before give path follow.
  • you're referencing both _nodetouchedfirst , nodetouchedfirst, "car" , "car1".
  • you're following path asoffset:yes, orienttopath:no, duration:2 (rather asoffset:no, orienttopath:yes, speed:2).
  • direction doesn't correspond sknode zrotation property.

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -