Objective c Cocos2d精灵生成器移动精灵并发射弹药

Objective c Cocos2d精灵生成器移动精灵并发射弹药,objective-c,cocos2d-iphone,Objective C,Cocos2d Iphone,我正在学习sprite builder教程,并试图改变一些东西,看看它是如何工作的,我陷入了困境,需要帮助。 这是我的密码 问题标记为//我需要查看您用来调用方法Left的方法。。。但是,要使按钮操作在开始时而不是完成时执行,请使用以下方法:'-(void)cctouchesBegind:(NSSet*)touchesEvent:(UIEvent*)event'上面的代码是我迄今为止拥有的所有代码…在主场景构造函数上添加以下行:'[self-setistouched:YES];只需添加以下方法:

我正在学习sprite builder教程,并试图改变一些东西,看看它是如何工作的,我陷入了困境,需要帮助。 这是我的密码
问题标记为//我需要查看您用来调用方法Left的方法。。。但是,要使按钮操作在开始时而不是完成时执行,请使用以下方法:'-(void)cctouchesBegind:(NSSet*)touchesEvent:(UIEvent*)event'上面的代码是我迄今为止拥有的所有代码…在主场景构造函数上添加以下行:'[self-setistouched:YES];只需添加以下方法:-(void)cctouchsbegind:(NSSet*)touchswithevent:(UIEvent*)event'然后您应该能够让精灵在触摸开始时做您想要的事情。我假设您没有将CCMenuItem用于按钮,而只是使用触摸功能。注意:只需添加方法,实现它,您不必使用它。该应用程序将自动为您的电脑实现这一点。
static const CGFloat scrollSpeed = 150.f;
@implementation MainScene{
CCNode *hero;
CCPhysicsNode *physicsNode;
}

- (void)didLoadFromCCB {
self.userInteractionEnabled = TRUE;
}

- (void)update:(CCTime)delta {
hero.position = ccp(hero.position.x + delta * scrollSpeed, hero.position.y);
physicsNode.position = ccp(physicsNode.position.x - (scrollSpeed *delta), physicsNode.position.y);
}

- (void)jump {//make the hero jump (still deciding on 400 or 600)
[hero.physicsBody applyImpulse:ccp(0, 400.f)];
}

- (void)fire {  
CCNode* ammo = [CCBReader load:@"Ammo"];
ammo.position = ccpAdd(hero.position, ccp(10, 20));
// add the ammo to the physicsNode of this scene (because it has physics enabled)
[physicsNode addChild:ammo];

// manually create & apply a force to launch the knife
CGPoint launchDirection = ccp(1, 0);
CGPoint force = ccpMult(launchDirection, 8000);
[ammo.physicsBody applyForce:force];
}

- (void)left { <---- How can I make the hero move based on how long the button is pressed?
CGPoint moveDirection = ccp(-1, 0);
CGPoint force = ccpMult(moveDirection, 8000);
[hero.physicsBody applyForce:force];
}

- (void)right { <---- How can I make the hero move based on how long the button is     pressed?
CGPoint moveDirection = ccp(1, 0);
CGPoint force = ccpMult(moveDirection, 8000);
[hero.physicsBody applyForce:force];
}

- (void)retry {
// reload this level
[[CCDirector sharedDirector] replaceScene: [CCBReader loadAsScene:@"MainScene"]];
}
- (void)exit {
CCScene *menuScene = [CCBReader loadAsScene:@"MenuScene"];
[[CCDirector sharedDirector] replaceScene:menuScene];
}

@end