COCOS2D粒子效果碰撞

3
我不知道为什么它不能工作。粒子效果位于屏幕左下方,而不是它所碰撞的部分。
在.h文件中。
    CCParticleExplosion *starsExplosion;

在.M文件中
位于碰撞下面

        if(distance < 30) {
        starsCollected += 100;
        [_stars removeObject:stars];

        //Stars Explosion
        //starsExplosion.position = ccp(stars.contentSize.width, stars.contentSize.height);
        starsExplosion = [[CCParticleExplosion alloc] init];
        starsExplosion.position = ccp(stars.position.y, stars.position.x);
        starsExplosion.texture = [[CCTextureCache sharedTextureCache] addImage:@"star-icon.png"];

        [self addChild:starsExplosion];

        [self removeChild:stars cleanup:YES];
    }

我尝试使用ContentSize.Widthheight=,但没有成功。

我还尝试使用Position.xy=,同样不行。


1
我不认为这是你问题的根源,但在设置位置时,你是否交换了x和y? - Tomas Andrle
1个回答

3
你把x和y坐标搞反了。我知道,在自己的代码中很难发现错误,你可能当时没有清晰地思考。
将此更改为:
starsExplosion.position = ccp(stars.position.y, stars.position.x);

翻译成:

starsExplosion.position = ccp(stars.position.x, stars.position.y);

1
哇,这段代码居然能用。非常感谢。我没有仔细阅读它。 - Ranbir Aulakh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接