我有一个CCSprite和一个CCParticleSystemQuad,它们都是CCLayer的子级。在我的更新方法中,我将发射器的位置设置为精灵的位置,以便跟踪周围的精灵。烟雾会像你期望的那样落在精灵的底部,即使你移动精灵,烟雾似乎也是背景层的一部分。Cocos2d - 如何使单个粒子跟随图层,而不是发射器?
问题来了,如果我匹配他们的旋转。现在,例如,如果我的精灵来回晃动,烟雾挥动成弧形,并出现在精灵身上。
如何让烟雾继续沿着父层直线而不是随着精灵旋转?当我移动它们时,它们不会与精灵一起转换,那么为什么它们会随之旋转呢?
编辑:添加代码...
- (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.
出 - 感谢您的建议,但它仍然与精灵一起来回摆动。我真的很困惑,为什么翻译和旋转的差异如此之大。我看到的唯一区别是我通过直接更改其位置并旋转动作来移动精灵。 – Steve