2011-04-10 2 views
1

이 같은 적을 추가 해요 : CCMoveTo 업데이트 된 플레이어 postition을하지 않습니다 ..... (아이폰,적인 Cocos2D)

-(void)addEnemy { 
    if ([spawnedEnemies count] < 25) { 
     CCSprite* sprite = [CCSprite spriteWithFile:@"white.png"]; 
     float randomX = arc4random() % 480; 
     float randomY = arc4random() % 320; 

     sprite.position = ccp(randomX,randomY); 
     [spawnedEnemies addObject:sprite]; 
     [self addChild:sprite]; 

     [sprite runAction:[CCMoveTo actionWithDuration:5 position:player.position]]; 
    } } 

하지만 내 플레이어가 스프라이트를 이동하면 여전히 마지막으로 이동

플레이어 자세 ... 때문에 내 눈금이 시도 그 :

- (무효) 틱 (ccTime) δ {

for (CCSprite *sp in spawnedEnemies) { 
    [sp stopAllActions]; 
    [sp runAction:[CCMoveTo actionWithDuration:5 

총수 : player.position]; }}

하지만 난 (단지 reallllllllyyyyyyyyy 느린가 이동 이동 중지하면 적에만 이동합니다 때문에 내가 그것을 [SP stopAllActions] 내가 지금 무엇을해야

를 호출 이동할 때마다?

편집 : *편집 : * 편집 : *편집 : * 편집 : *편집 : * 편집 : 이 * 편집이 : 지금 내가이 일을하고있어 플레이어가 을 이동하지만, 문제가있을 경우에도 적들이 플레이어에게 이동 : 더 가까운 적 (이다 * 편집 플레이어) 이동 속도가 느립니다 ... 어떻게 해결할 수 있습니까?

//function to apply a velocity to a position with delta 
static CGPoint applyVelocity(CGPoint velocity, CGPoint position, float delta){ 
    return CGPointMake(position.x + velocity.x * delta, position.y + velocity.y * delta); 
} 


-(void)tick:(ccTime)delta {  
    for (CCSprite *sp in spawnedEnemies) { 
     CGPoint m = ccpSub(player.position, sp.position); 
     sp.position = applyVelocity(m, sp.position, 1.0/60.0f); 
    } 
} 

답변

관련 문제