2013-03-31 1 views
0

그래서 내 게임 나는 배열에 여러 스프라이트를 추가하고 있고 더 많은 스프라이트 나는 빨리 내 게임을 실행하기 시작 추가? 내 질문에 것 같아요,이 같은 스프라이트 추가 및 For 루프에서 해당 속성을 호출하는 문제를 만들지 않습니다? 또는 문제가 다른 곳에서 발생합니다. 나는 "지상"스프라이트를 더 추가하면 점프 높이, 이동 속도 및 스크롤 속도가 증가한다는 것을 확인했습니다. 이 문제를 해결하기 위해 기와로 전환해야합니까?스프라이트는

gravity -= 2 ; 


for(CCSprite *ground in boxes){ 

    if(CGRectIntersectsRect(_character.boundingBox, ground.boundingBox) && !jump && (_character.position.y > ground.position.y + ground.contentSize.height/2 -20) && _character.position.x > ground.position.x - ground.contentSize.width/2 && facingLeft) 
    { 
     _character.position = ccp(_character.position.x, ground.position.y + ground.contentSize.height/2 + _character.contentSize.height/2-.001); 
     falling = NO; 
     onGround = YES; 
     gravity = 0; 
     if(!_moving){ 
      [_character setDisplayFrame: 
      [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"1-1.png"] ]; 
     } 
    } 

    else if(CGRectIntersectsRect(_character.boundingBox, ground.boundingBox) && !jump && (_character.position.y > ground.position.y + ground.contentSize.height/2-20) && _character.position.x < ground.position.x + ground.contentSize.width/2 && !facingLeft) 
    { 
     _character.position = ccp(_character.position.x, ground.position.y + ground.contentSize.height/2 + _character.contentSize.height/2-.001); 
     falling = NO; 
     onGround = YES; 
     gravity = 0; 
     if(!_moving){ 
      [_character setDisplayFrame: 
      [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"1-1.png"] ]; 
     } 
    } 

    else if(CGRectIntersectsRect(_character.boundingBox, ground.boundingBox) && (targetX <= 0) && (_character.position.y +_character.contentSize.height < ground.position.y + ground.contentSize.height) && (_character.position.x > ground.position.x) && (gp.isControlling && (gp.controlQuadrant == 2 || gp.controlQuadrant == 3))) 
    { 
     backgroundX = 0; 
     targetX = 0; 

    } 
    else if(CGRectIntersectsRect(_character.boundingBox, ground.boundingBox) && (_character.position.y +_character.contentSize.height < ground.position.y + ground.contentSize.height) && (_character.position.x < ground.position.x) && (gp.isControlling && (gp.controlQuadrant == 0 || gp.controlQuadrant == 1))) 
    { 

     backgroundX = 0; 
     targetX = 0; 
    } 

    else 
    { 
     normalForce = 0; 
     jump = NO; 
     falling = YES; 
     doubleJump = 0; 
    } 


    // totalForce = normalForce + gravity; 
    // [_character setPosition:ccp(_character.position.x, _character.position.y+totalForce)]; 
     } 
totalForce = normalForce + gravity; 
if(gravity == 0) { 
    falling = NO; 
    NSLog(@"Gravity = 0"); 
} 

[_character setPosition:ccp(_character.position.x + targetX, _character.position.y + totalForce)]; 
: 나는 배열에 이미지를 추가하고 내 캐릭터 스프라이트와 접지 사이의 교차로 같은 것들에 대해 검사 할 때이 같은 루프를 사용하는 경우

CCSprite *ground = [CCSprite spriteWithFile:@"testlevel 5.png"]; 
      [ground setPosition:ccp(520, 10)]; 
      [ground setScale:1.0]; 
      //[ground setScaleX:(2 * ground.contentSize.width)]; 
      [self addChild:ground z:0]; 
      [boxes addObject:ground]; 

      ground = [CCSprite spriteWithFile:@"testlevel 4.png"]; 
      [ground setPosition:ccp(ground.contentSize.width/2 +400, -50)]; 
      [ground setScale:1.0]; 
      //[ground setScaleX:(2 * ground.contentSize.width)]; 
      [self addChild:ground z:0]; 
      [boxes addObject:ground]; 

      ground = [CCSprite spriteWithFile:@"testlevel 3.png"]; 
      [ground setPosition:ccp(ground.contentSize.width/2 +280, -10)]; 
      [ground setScale:1.0]; 
      //[ground setScaleX:(2 * ground.contentSize.width)]; 
      [self addChild:ground z:0]; 
      [boxes addObject:ground]; 

이 위의 세그먼트입니다 점프는 중력의 약 10 intager 추가 간단한 버튼에 의해 제어된다}

. I는 중력과 같습니다 내 틱 기능을 실행하는 타이머가 있습니다

gravity -=1; 

을하고 내 문자 위치로 그 값을 추가, 중력이 0으로 설정됩니다 때 상자의 상단에. 왼쪽/오른쪽 플레이어는 틱 기능으로 속도를 업데이트하는 조이스틱으로 제어됩니다. 더 많은 정보가 필요하다면 알려주세요. 그러나 다시 말하면, 배열에 스프라이트를 추가하면 알 수없는 이유로 속도가 변경됩니다. 어떤 도움이라도 대단히 감사 할 것입니다. 여기

코드에서 점프

-(void)jumpTapped 
{ 
    NSLog(@"PRESSED"); 
    if(!falling && onGround){ 
     doubleJump += 1; 
     gravity += 10; 
     jump = YES; 
     onGround = NO; 
     NSLog(@"JUMPING"); 
    } 
} 
+0

에 대한 전체 내용을 쓸 수 있습니까? (상자에 CCSprite * 접지) 코드? 나는 그것이 그래서 간단하게 코드를 찾고 후 무엇을 말할 수에서 모든 –

+0

거기에있는 코드를 함께 할 수있는 뭔가가 느낌이있는 것은 I가 추측 오전하기 만 문을 반환하는 경우 중 하나가 될해야한다는 것입니다 사실, 맞습니까? – user1569940

+0

해야 당신이 –

답변

0

에 대한 무효 기능입니다

} else { 
    normalForce = 0; 
    jump = NO; 
    falling = YES; 
    doubleJump = 0; 
} 

은 NO 그래서 처음 스프라이트는 루프를 통해 실행과 일치하지 않는 경우에 점프를 설정 이러한 if 문 중 일부는 기본값으로 설정됩니다. 그러면 다음 번에 점프를 통과 할 때 NO로 설정되어 버튼을 눌렀을 때부터 초기 값을 던지므로 플레이어가 뛰지 않게하는 코드는 절대 실행되지 않습니다.

+0

점프는 날씨가 보이지 않거나 버튼을 누르지 않았는지 확인하는 것입니다. 추가로 문제를 해결할 수있었습니다. 중력 <0 절 내 if 문에. 정말 고맙습니다! 이것은 나에게 아주 두통을주고 있었다. 그러나 지금 그 고정 시키게된다! 가능한 한 충돌 할 수있는 객체의 좌표를 입력하는 시간을 절약하기 위해 곧 타일로 전환 할 것입니다. – user1569940

+0

다행이라면, 당신의 if 서술문은 점프의 충돌 탐지를 기반으로합니다. 즉 if 문에서 &&!라고 말했습니다.jump && 점프가 NO로 설정된 경우 if 문을 생략합니다. –

관련 문제