文字を画面上にジャンプさせることを想定しているIBActionを持っていますが、ますます下に移動します。この関数はちょうど呼び出されるべきです、そして、私は地面とのあらゆる衝突に置かないので、キャラクターは 'ジャンプ'して、スクリーンからまっすぐ落ちます。なぜこれが起こっているのか? timは、chracaterを保持する私のUIImageViewの名前です、btw。Iphone、objective-cプラットフォームのためのJumpメソッドの作成方法
-(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;
}*/
}
}