我有这个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;
}*/
}
}