我有這個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;
}*/
}
}