2009-07-11 60 views
0

我有这个IBAction是假设在屏幕上跳转的一个字符,但是当它调用它只是将字符向上移动一次,然后每次调用后字符只是越来越多地下移。这个功能应该被调用,然后角色会'跳'起来,然后直接从屏幕上掉下来,因为我没有与地面发生任何碰撞。任何建议为什么发生这种情况?蒂姆是我的UIImageView的名称,持有chracater,顺便说一句。Iphone,objective-c如何为平台游戏制作跳跃方法

-(IBAction)Jump:(id)sender 

int jumpSpeed = JumpSpeedLimit; CGPoint newCenter = tim.center;

if(!mainJumping){ 
    //then start jumping 
    mainJumping = TRUE; 
    jumpSpeed = JumpSpeedLimit*-1; 
    newCenter.x -= jumpSpeed; 
    tim.center = newCenter; 

} else { 
    //then continue jumping if already in the air 
    //crazy math that I won't explain 
    if(jumpSpeed < 0){ 
     jumpSpeed *= 1 - JumpSpeedLimit/75; 
     if(jumpSpeed > -JumpSpeedLimit/5){ 
      jumpSpeed *= -1; 
     } 
    } 
    if(jumpSpeed > 0 && jumpSpeed <= JumpSpeedLimit){ 
     jumpSpeed *= 1 + JumpSpeedLimit/50; 
    } 
    newCenter = tim.center; 
    newCenter.x -= jumpSpeed; 
    tim.center = newCenter; 
    /* 
    //if hits the floor, then stop jumping 

    if(tim.center.x >= 360 - tim.bounds.size.height){ 
     mainJumping = FALSE;    
     newCenter = tim.center; 
     newCenter.x = 360 - tim.bounds.size.height; 
     tim.center = newCenter; 
    }*/ 

} 

}

回答

1

你压根设计这个错误。您希望按下“跳转”按钮设置某种标志,然后在您的游戏引擎代码中处理该标志。