У меня есть CCSprite и CCParticleSystemQuad, которые оба являются потомками CCLayer. В моем методе обновления я установил позицию эмиттера в положение спрайта, чтобы он отслеживал спрайт вокруг. Скопление дыма выпадает из нижней части спрайта, как и следовало ожидать, и даже если вы перемещаете спрайт вокруг, дым кажется частью фонового слоя.
Проблема возникнет, если я сопоставлю их вращения. Например, если мой спрайт качается взад-вперед, клубы дыма раскачиваются по дуге и кажутся прикрепленными к спрайту.
Как сделать так, чтобы клубы дыма продолжались вдоль родительского слоя по прямой линии и не вращались вместе со спрайтом? Они не переводятся со спрайтом, когда я его перемещаю, так почему они вращаются вместе с ним?
РЕДАКТИРОВАТЬ: добавление кода ...
- (id)init
{
if (!(self = [super init])) return nil;
self.isTouchEnabled = YES;
CGSize screenSize = [[CCDirector sharedDirector] winSize];
sprite = [CCSprite spriteWithFile:@"Icon.png"]; // declared in the header
[sprite setPosition:ccp(screenSize.width/2, screenSize.height/2)];
[self addChild:sprite];
id repeatAction = [CCRepeatForever actionWithAction:
[CCSequence actions:
[CCRotateTo actionWithDuration:0.3f angle:-45.0f],
[CCRotateTo actionWithDuration:0.6f angle:45.0f],
[CCRotateTo actionWithDuration:0.3f angle:0.0f],
nil]];
[sprite runAction:repeatAction];
emitter = [[CCParticleSystemQuad particleWithFile:@"jetpack_smoke.plist"] retain]; // declared in the header - the particle was made in Particle Designer
[emitter setPosition:sprite.position];
[emitter setPositionType:kCCPositionTypeFree]; // ...Free and ...Relative seem to behave the same.
[emitter stopSystem];
[self addChild:emitter];
[self scheduleUpdate];
return self;
}
- (void)update:(ccTime)dt
{
[emitter setPosition:ccp(sprite.position.x, sprite.position.y-sprite.contentSize.height/2)];
[emitter setRotation:[sprite rotation]]; // if you comment this out, it works as expected.
}
// there are touches methods to just move the sprite to where the touch is, and to start the emitter when touches began and to stop it when touches end.