2017-09-11 12 views
0

私は楽しいためにこのシンプルなゲームを作成しています。私はいくつかの問題に遭遇しました。オブジェクトの速度を変更する

落下物に新しい速度を設定する。ユーザーのスコアが上がるにつれて、速度を変えて少しずつ増やしたいと思っています。しかし、現在のスピードは、スピードを増やすだけで増やしたいので、スピードが上がるので、スピードが上がります。

これが私の活動です:任意の洞察力や助けを事前に

public void startTimer() { 
    timer = new Timer(); 
    initializeTimerTask(); 
    timer.schedule(timerTask, 100, 20); 

} 
public void stoptimertask() { 
    if (timer != null) { 
     timer.cancel(); 
     timer = null; 
    } 
} 
public void initializeTimerTask() { 
    timerTask = new TimerTask() { 
     public void run() { 
      handler.post(new Runnable() { 
       public void run() { 
        goDown(); 
       } 
      }); 
     } 
    }; 
} 

public void goDown() { 
    frame = (FrameLayout) findViewById(R.id.frame); 
    frameHeight = frame.getHeight(); 
    boxY = (int) txtWord.getY(); 
    boxSizeY = txtWord.getHeight(); 

    if(scoreCount >= 0) 
    { 
     boxY += 1; 
    } 
    if(scoreCount >= 5) 
    { 
     boxY += 2; 
    } 
    if(scoreCount >= 10) 
    { 
     boxY += 3; 
    } 

    txtWord.setY(boxY); 

    if (boxY > frameHeight - boxSizeY) { 
     boxY = frameHeight - boxSizeY; 
     stoptimertask(); 
     displayGameOver(); 
    } 

} 

ありがとう! :D

答えて

2
if(scoreCount >= 0 && scoreCount < 5) 
{ 
    boxY += 1; 
} 
if(scoreCount >= 5 && scoreCount < 10) 
{ 
    boxY += 2; 
} 
if(scoreCount >= 10) 
{ 
    boxY += 3; 
} 

スピードの問題でこれを試してください。

+0

私はスピードトラブルに関連するように私の質問を変更しました。私はランダムな位置に解決策を見つけました。助けてくれてありがとう! –

+0

あなたは大歓迎です! – Elinor

関連する問題