objective c - Need help incorporating "Preform Selector: WithObject: AfterDelay:" with the SKScene being paused -
i need incorporating the
preformselector: withobject: afterdelay:
with skscene being paused. making game there pause button pauses scene. this, not affect the
preformselector: withobject: afterdelay:
function calls "reload" function. without fixed user can fire shot, press pause, wait reload function called, un-pause, , shoot. makes user can continuously fire without having reload in "game time". there way fix this?
you shouldn't using performselector:withobject:afterdelay:
, because keeping track of timing , storing selectors , objects etc. method cumbersome.
instead, make use of spritekit's +[skaction waitforduration:]
action.
you want following (i'm assuming code takes place somewhere in 1 of scene's methods):
// replace 2.0 below long want wait, in seconds skaction *waitaction = [skaction waitforduration:2.0]; // i'm assuming "reload" method method declared in scene's // class , not other class, i'm using "self" target here. skaction *reloadaction = [skaction performselector:@selector(reload) ontarget:self]; skaction *sequenceaction = [skaction sequence:@[waitaction, reloadaction]]; // since i'm assuming in scene implementation, `self` here // refers scene node. [self runaction:sequenceaction];
since actions can paused , resumed, when pause scene self.paused = yes;
actions paused , resume left off when later unpause scene.
Comments
Post a Comment