ios - Modify SKActions during the game -


i developing game enemies sknodes in own classes. within skscene spawning mobs via allocing them , calling specific method spawning.

however, when spawned each mob defined set of actions run during lifetime. 1 example 1 specific mob is:

    skaction *moveleft = [skaction movetox:0 - (fragment.size.width/2) + (width / 2) duration:1.0];     skaction *moveright = [skaction movetox:(fragment.size.width / 2) - (width / 2) duration:1.0];      skaction *sequence = [skaction sequence:@[moveleft, moveright]];     skaction *bounceonwalls = [skaction repeatactionforever:sequence];      [enemy runaction:bounceonwalls]; 

so, question. how can modify specific skaction after been created? change lets speed of moveleft enemies have skaction.

you can run action key :

skaction *moveleft = [skaction movetox:0 - (fragment.size.width/2) + (width / 2) duration:1.0];     skaction *moveright = [skaction movetox:(fragment.size.width / 2) - (width / 2) duration:1.0];      skaction *sequence = [skaction sequence:@[moveleft, moveright]];     skaction *bounceonwalls = [skaction repeatactionforever:sequence];      [enemy runaction:bounceonwalls withkey:@"moving"]; //run action key 

and when need change speed on nodes running action, can use enumeratechildnodeswithname method. this:

[parentnode enumeratechildnodeswithname:name usingblock:^(sknode *node, bool *stop){          if([node actionforkey:@"moving"]){               skaction* action = [node actionforkey:@"moving"];             action.speed = 1.5f;          }      }]; 

you change dynamically duration of actions , affect in way on speed of moving nodes, think changing speed of action directly better choice. take @ both answers in example on how can change duration parameter dynamically.


Comments