我有两个 A 类和 B 类。我在 A 中创建 B 类的对象:
B *objectB = [B classInitWithParamiters:paramiters];
[self addChile:objecTB z:1 tag:varForTag];
varForTag++;
我多次调用此代码。
这是 Bh 文件:
@interface Chicken : CCSprite <CCTargetedTouchDelegate> {
CCsprite *spriteB;
}
+ (id) classInitWithParamiters :(int) paramiters;
这是Bm文件:
+ (id) classInitWithParamiters :(int) paramiters
{
return [[[self alloc] init] autorelease];
}
- (id) init
{
if( (self = [super init]) ) {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:NO];
spriteB = [[CCSprite alloc] initWithFile:@"image.png"];
spriteB.position = ccp(160, 240);
[self addChild:spriteB];
}
return self;
}
- (void) update :(ccTime)dt
{
NSLog(@"This is a Class B");
}
- (void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint location = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
if(CGrectContainsPoint([spriteB boundingbox], location))
NSLog(@"touch moved in the class B");
}
我的问题是:当我用 C 类的场景替换 A 场景时,B 类的方法更新会停止记录,但是如果我触摸屏幕中间并移动手指,它会记录“B 类中的触摸移动” .
我做错了什么?这些 B 类对象在替换场景后不应自动释放。B 类是 CCSprite 和 A - CCLayer 的子类;