【问题标题】:COCOS2D Particle Effect CollisionCOCOS2D 粒子效果碰撞
【发布时间】:2023-04-03 17:03:01
【问题描述】:

我不知道为什么它不起作用。粒子效果位于屏幕左下角,而不是碰撞的部分。

在.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 =,又是运气。

【问题讨论】:

  • 不是我认为这是您问题的根源,但您在设置位置时不是交换 x 和 y 吗?

标签: cocos2d-iphone particles


【解决方案1】:

您切换了 x 和 y 坐标。我知道,在你自己的代码中很难看到错误,你可能只是当时没有想清楚。

改变这个:

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

到这里:

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

【讨论】:

  • 哇,该代码确实有效。太感谢了。我没有正确阅读它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多