【发布时间】:2014-04-10 18:31:19
【问题描述】:
最近开始探索cocos2d v3.0。我正在尝试一些基本的东西,但遇到了一些麻烦。
基本上,我将 CCSprite 子类化以创建 Square 对象。之后将方形对象添加到我的 HelloworldScene 中,我想接收对我的方形精灵的触摸。由于某种原因,它不起作用。
这是代码 --头文件
#import "CCSprite.h"
@interface Square : CCSprite
@end
implementaion file
#import "Square.h"
#import "cocos2d.h"
@implementation Square
-(id)init {
// Apple recommend assigning self with supers return value
self = [super init];
if (!self) return (nil);
self.contentSize = [[CCDirector sharedDirector] viewSize];
self.userInteractionEnabled = YES;
return self;
}
-(void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
CCLOG(@"touch received");
}
@end
这是 hello world init 方法
- (id)init
{
// Apple recommend assigning self with supers return value
self = [super init];
if (!self) return(nil);
Square *_square = [[Square alloc] initWithImageNamed:@"background.png"];
[_square setPosition:CGPointZero];
[self addChild:_square];
// done
return self;
}
当我运行代码时,我可以在屏幕上看到精灵,但是当我点击它时,什么也没有发生,触摸开始永远不会被调用。我在这里想念什么?
【问题讨论】:
标签: ios objective-c cocos2d-iphone