ios - Move a SKSpriteNode with a single tap, but move continously when long tap - Sprite Kit -


i'm trying change skactions of existing sprite kit tutorial project, i'm running issues when comes movement. tutorial , github project here:

https://www.codefellows.org/blogs/simple-sprite-kit-game-tutorial-part1

https://github.com/megharastogi/gametutorial

as can see in code below, each tap moves node once. how change long tap move continuous move node? tried few things repeatactionforever, didn't work well.

-(void)addship {         //initalizing spaceship node         ship = [skspritenode spritenodewithimagenamed:@"spaceship"];         [ship setscale:0.5];         ship.zrotation = - m_pi / 2;          //adding spritekit physicsbody collision detection         ship.physicsbody = [skphysicsbody bodywithrectangleofsize:ship.size];         ship.physicsbody.categorybitmask = shipcategory;         ship.physicsbody.dynamic = yes;         ship.physicsbody.contacttestbitmask = obstaclecategory;         ship.physicsbody.collisionbitmask = 0;         ship.physicsbody.usesprecisecollisiondetection = yes;         ship.name = @"ship";         ship.position = cgpointmake(120,160);         actionmoveup = [skaction movebyx:0 y:30 duration:.2];         actionmovedown = [skaction movebyx:0 y:-30 duration:.2];          [self addchild:ship]; }  - (void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     uitouch *touch = [touches anyobject];     cgpoint touchlocation = [touch locationinnode:self.scene];     if(touchlocation.y >ship.position.y){         if(ship.position.y < 270){             [ship runaction:actionmoveup];         }     }else{         if(ship.position.y > 50){              [ship runaction:actionmovedown];         }     } } 

- (void)didmovetoview:(skview *)view {     uilongpressgesturerecognizer *tapper = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@selector(tappedscreen:)];     tapper.minimumpressduration = 0.1;     [view addgesturerecognizer:tapper]; }  - (void)tappedscreen:(uitapgesturerecognizer *)recognizer {     float touchy = [self convertpointfromview:[recognizer locationinview:self.view]].y;     skspritenode *ship = [self childnodewithname:@"ship"];     if (recognizer.state == uigesturerecognizerstatebegan) {         if(touchy >ship.position.y){             [ship runaction:[skaction repeatactionforever:actionmoveup] withkey:@"longtap"];         }else{             [ship runaction:[skaction repeatactionforever:actionmovedown] withkey:@"longtap"];         }     }     if (recognizer.state == uigesturerecognizerstateended) {         [ship removeactionforkey:@"longtap"];     } } 

add these 2 methods in code.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -