Help to deal with the management of the hero. There is a scene, a hero is placed in it, threw 3 buttons onto the scene (CCNode), to move left, right and jump. The control works, but when the hero goes further along the "map", then when you release and then press any button, the movement does not occur ... As if the frame remains at the beginning of the map, and then the button’s sprit stand fine, they move along with the hero. I work in xcode and spritekit. The code is presented below:

-(void)update:(CCTime)delta{ float rad = _mainHero.rotation *(M_PI/180); if (clickedRight) { NSLog(@"нажата кнопка"); _mainHero.position = ccpAdd(_mainHero.position, ccp(delta *80, 0)); }else if (clickedLeft) { _mainHero.position = ccpAdd(_mainHero.position, ccp(-1*delta *80, 0)); } if (clickedJump) { _mainHero.position = ccpAdd(_mainHero.position, ccp(sin(rad) * delta *150, cos(rad)*delta*150)); } } -(void)touchMoved:(CCTouch *)touch withEvent:(CCTouchEvent *)event{ _follow = [CCActionFollow actionWithTarget:_mainHero worldBoundary:self.boundingBox]; [_contentNode runAction:_follow]; CGPoint touchLocation = [touch locationInNode:_contentNode]; if (CGRectContainsPoint([_btnRight boundingBox], touchLocation)) { CCLOG(@"пробежалась по кнопке НАПРАВО !!!!---->>>"); } self.position = ccp(0, 0); if (CGRectContainsPoint([_btnRight boundingBox], touchLocation)) { clickedRight = YES; CCLOG(@"нажато на кнопку НАПРАВО !!!!---->>>"); clickedLeft = NO; clickedJump = NO; } if (CGRectContainsPoint([_btnLeft boundingBox], touchLocation)) { clickedLeft = YES; clickedRight = NO; clickedJump = NO; CCLOG(@"нажато на кнопку НАЛЕВО !!!!---->>>"); } if (CGRectContainsPoint([_btnJump boundingBox], touchLocation)) { clickedJump = YES; clickedLeft = NO; clickedRight = NO; CCLOG(@"нажато на кнопку ПРЫЖОК !!!!---->>>"); } } -(void)touchEnded:(CCTouch *)touch withEvent:(CCTouchEvent *)event{ clickedJump = NO; clickedLeft = NO; clickedRight = NO; CCLOG(@"END---->>>"); } - (void)touchBegan:(CCTouch *)touch withEvent:(CCTouchEvent *)event { [self launchPenguin]; // ensure followed object is in visible are when starting _follow = [CCActionFollow actionWithTarget:_mainHero worldBoundary:self.boundingBox]; [_contentNode runAction:_follow]; CGPoint touchLocation = [touch locationInNode:_contentNode]; } -(id)init{ if (self = [super init]) { self.multipleTouchEnabled = YES; clickedJump = NO; clickedLeft = NO; clickedRight = NO; self.position = ccp(0, 0); _follow = [CCActionFollow actionWithTarget:_mainHero worldBoundary:self.boundingBox]; [_contentNode runAction:_follow]; } return self; } 
  • makeschool.com/tutorials/getting-started-with-spritebuilder/ ... did it on the tutor, there they did the RESTART button, I also added the button, she moved along with the hero, and her event worked, but with the motion buttons it did not work, since I didn’t understand how to make the hero move while the button is pressed ... - PupkinsDeveloper

0