【发布时间】:2013-05-25 08:59:35
【问题描述】:
我有一个 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.
【问题讨论】:
标签: iphone ios cocos2d-iphone