2012-07-06 5 views
2

눈 입자 효과가 내 스프라이트를 따라 가기를 원하지만 몇 가지 방법을 시도했지만 일어나는 모든 일은 눈이 계속 따라 가지 않고 멈추게됩니다. 나는이 튜토리얼을 한 번 해보았는데 (발견하자마자 게시 할 것입니다.) 그게 어떻게 불이 났는지 전혀 보여주지는 않지만 전혀 작동하지 않았다는 것을 보여줍니다. 모든 자습서 또는 제안을 주시면 감사하겠습니다. 내가 화면에서 적을 만들라고 말하는 코드 조각에 코드를 추가해야한다고 생각합니다. 코드로받지 않고cocos2d에서 스프라이트에 따라 입자 효과를 얻으려면 어떻게해야합니까?

[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]; 
    } 
    } 
+1

http://pocketworx.com/?p=147 –

+0

네가 읽었습니까? 전혀 작동하지 않았습니다. –

+0

눈에 미치는 영향이 무엇입니까? –

답변

0

매우 간단한 논리 :

난 스프라이트를 생성하고 그것의 위치 (X, Y)를 얻었다. 각 스프라이트에 대해 CCParticleSystem을 생성하고 필요한 입자 유형을 지정하고 속도를 생성합니다. CCParticleSystem 위치가 스프라이트와 동일한 (x, y) 위치로 설정되며 이제는 스프라이트의 (x, y) 위치가 업데이트됩니다.

스프 라이트와 CCParticleSystem이 돌아 다니면서이 위치 (x, y)는 간격 단계 시간별 일정 방법에서 일정하게 무작위로 업데이트됩니다.

희망이 있습니다.

0

은 내가 -(void) update:(ccTime)dt 방법이라고이

- (void) updateParticleSystem:(ccTime)dt { 
vehicleParticleSystem.position = ccp(_ship.position.x - _ship.contentSize.width/3, _ship.position.y - _ship.contentSize.height/3); 
} 

vehicleParticleSystem = [CCParticleSystemQuad particleWithFile:@"vehicleParticle.plist"]; 
vehicleParticleSystem.position = ccp(_ship.position.x - _ship.contentSize.width/3, _ship.position.y - _ship.contentSize.height/3); 
if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) { 
    vehicleParticleSystem.scale = 0.5; 
} 
[self addChild:vehicleParticleSystem z:-1]; 

및 업데이트의 위치를 ​​않습니다.

선박은 조이패드를 통해 사용자에 의해 이동됩니다.

희망이 도움이됩니다. 입자의 위치는 엔진 효과를 내기 위해 차량 뒤쪽에 약간 있습니다.

+0

@john Doe :이게 도움이 되었습니까? – jarryd

0

내가 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, 
에서,이를 찾았

you should set it like

myparticleSystem.positionType=kCCPositionTypeGrouped;

는 도움이되기를 바랍니다.

0

업데이트 방법을 이용하여 입자 위치를 업데이트하려고 했습니까?

나는 나의 게임 중 하나에서 다음 줄과 같은 일을하고 그리고 난 당신이

 
    -(void) update:(CCTime)delta{ 

     _sprite.position = CGPointMake(newXPosition, newYPosition); 

     _fire.position = CGPointMake(_sprite.position.x, _sprite.position.y); 

    } 

나는 그것이 도움이되기를 바랍니다 기대 생각대로 작동한다!

1

입자 이미 터의 위치를 ​​스프라이트로 업데이트 할 필요가 없습니다. 파티 시스템을 스프라이트에 자식으로 추가 할 수 있습니다. 입자 시스템은로 입력 할 필요가 않습니다

CCParticleSystem * booster = [CCParticleSystem particleWithFile:@"boosterParticles.plist"]; 
    //customize your particles' options 

    //assuming you have a sprite defined as _motherShip 
    [_motherShip addChild:booster]; 

    /* 
    * now that the particles are the _motherShip's child, you must remember 
    * to set the position relative to the mothership's origin... 
    */ 
    particles.position = ccp(15,0); 

을 ... 그래서 지금 _motherShip.position 변경, 부스터가 따를 때마다. 배와 함께 회전합니다.

관련 문제