gpt4 book ai didi

iphone - 如何在 cocos2d 中获得跟随 Sprite 的粒子效果?

转载 作者:行者123 更新时间:2023-12-03 21:03:22 26 4
gpt4 key购买 nike

我想要雪粒子效果跟随我的 Sprite ,我尝试了一些方法,但最终发生的只是雪将保持静止而不是跟随。我做了这个教程(我一找到它就会发布),它展示了它如何用火来做,但根本没有成功。任何教程或建议将不胜感激。我相信我必须在代码片段部分添加某种代码,其中显示“在屏幕外创建敌人”。

   [self schedule:@selector(gameLogicboss:) interval:180 ];        
[self schedule:@selector(updateboss:)];

-(void)addTarget1 {

Boss *target1 = nil;


if ((arc4random() % 2) == 0) {{
target1 = [WeakAndFastBoss boss];
}} else {
target1 = [WeakAndFastBoss boss];
}

// Determine where to spawn the target along the Y axis
CGSize winSize = [[CCDirector sharedDirector] winSize];
int minY = target1.contentSize.height/2;
int maxY = winSize.height - target1.contentSize.height/2;
int rangeY = maxY - minY;
int actualY = (arc4random() % rangeY) + minY;

// Create the target slightly off-screen along the right edge,
// and along a random position along the Y axis as calculated above
target1.position = ccp(winSize.width + (target1.contentSize.width/2), actualY);
[self addChild:target1 ];

// Determine speed of the target

int minDuration = target1.minMoveDuration;
int maxDuration = target1.maxMoveDuration;
int rangeDuration = maxDuration - minDuration;
int actualDuration = (arc4random() % rangeDuration) + minDuration;

// Create the actions
id actionMove = [CCMoveTo actionWithDuration:actualDuration position:ccp(-target1.contentSize.width/2, actualY)];


id actionMoveDone = [CCCallFuncN actionWithTarget:self
selector:@selector(spriteMoveFinished:)];
[target1 runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
target1.tag = 1;
[_targets addObject:target1];
}

-(void)gameLogicboss:(ccTime)dt {
[self addTarget1];
iterations_++;
}

- (void)updateboss:(ccTime)dt {
CGRect projectileRect = CGRectMake(projectile.position.x - (projectile.contentSize.width/2), projectile.position.y - (projectile.contentSize.height/2), projectile.contentSize.width, projectile.contentSize.height);

BOOL bossHit = FALSE;
NSMutableArray *targetsToDelete = [[NSMutableArray alloc] init];
for (CCSprite *target1 in _targets) {
CGRect target1Rect = CGRectMake(target1.position.x - (target1.contentSize.width/2), target1.position.y - (target1.contentSize.height/2), target1.contentSize.width, target1.contentSize.height);

if (CGRectIntersectsRect(projectileRect, target1Rect)) {

//[targetsToDelete addObject:target];
bossHit = TRUE;
Boss *boss = (Boss *)target1;
boss.hp--;
if (boss.hp <= 0) {
_score ++;
[targetsToDelete addObject:target1];
}
break;

}
}

for (CCSprite *target in targetsToDelete) {
[_targets removeObject:target];
[self removeChild:target cleanup:YES];
_projectilesDestroyed++;
if (_projectilesDestroyed > 2) {

}
}

if (bossHit) {
//[projectilesToDelete addObject:projectile];
[[SimpleAudioEngine sharedEngine] playEffect:@"explosion.caf"];
}
[targetsToDelete release];
}

-(void)spriteMoveFinishedboss:(id)sender {
CCSprite *sprite = (CCSprite *)sender;
[self removeChild:sprite cleanup:YES];
GameOverScene *gameOverScene = [GameOverScene node];
[gameOverScene.layer.label setString:@"You Lose"];
[[CCDirector sharedDirector] replaceScene:gameOverScene];

if (sprite.tag == 1) { // target
[_targets removeObject:sprite];
} else if (sprite.tag == 2) { // projectile
[_projectiles removeObject:sprite];
}
}

最佳答案

我在 CCParticleSystem.h 找到了这个

/** @typedef tCCPositionType possible types of particle positions /typedef enum {    /* Living particles are attached to the world and are unaffected by emitter repositioning. */    kCCPositionTypeFree,

/** Living particles are attached to the world but will follow the emitter repositioning.
Use case: Attach an emitter to an sprite, and you want that the emitter follows the sprite.
*/
kCCPositionTypeRelative,

/** Living particles are attached to the emitter and are translated along with it. */
kCCPositionTypeGrouped,



<p>you should set it like </p>

myparticleSystem.positionType=kCCPositionTypeGrouped;

希望有帮助。

关于iphone - 如何在 cocos2d 中获得跟随 Sprite 的粒子效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11364901/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com