我有一個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