我正在尝试开发cocos2d游戏。所以,我是cocos2d的新手,但我在iPhone上开发了很少的应用程序。我安装了cocos模板(v2.0),并使用box2d phisics创建了新项目。在这里,我可以看到一个带有块和一些菜单的演示项目。当我点击屏幕时,会出现新的块,并落在屏幕的按钮上。必须在这里实施:
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//Add a new body/atlas sprite at the touched location
for( UITouch *touch in touches ) {
CGPoint location = [touch locationInView: [touch view]];
location = [[CCDirector sharedDirector] convertToGL: location];
[self addNewSpriteAtPosition: location];
}
}所以,当触碰结束时,精灵就会出现。,但是当触碰开始或移动的时候,如何做一些事情呢?,我找不到茧的方法。我看了一些教程,有这样的方法:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
return YES;
}但它从来不叫..。我怎么了doung?
发布于 2012-02-02 10:57:12
实施
(BOOL)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event确保你有
self.isTouchEnabled = YES;.在该层的init方法中。
发布于 2012-02-02 10:51:14
执行:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
// whatever is needed here
return YES;
}在您的cocos2d类(相同的实现ccTouchesEnded)中,它将被调用。
https://stackoverflow.com/questions/9110991
复制相似问题