2014-09-11 4 views
0

나는 매초마다 점수를 1 포인트 씩 올리려고하지만 나는 제대로 작동하도록 고심하고있다.Libgdx 쇼 점수와 매초마다 점수를 1을 더함

예컨대

(의사 코드) :

int score = 0f // on create 

updateEverySecond() { 
    score += 1; 
    displayScore() 
} 

나는 또한 싶습니다 내 화면 상단의 점수를 표시하는 방법을 알고를 중심으로합니다.

내 전체 소스 코드 :

package com.ryanwarren.dodge.game; 

import com.badlogic.gdx.ApplicationAdapter; 
import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.Input.Keys; 
import com.badlogic.gdx.graphics.GL20; 
import com.badlogic.gdx.graphics.Texture; 
import com.badlogic.gdx.graphics.g2d.SpriteBatch; 
import com.badlogic.gdx.math.Vector2; 

public class libgdxGame extends ApplicationAdapter { 

SpriteBatch batch; 
Texture player; 

Vector2 position; 

float time = 0f; 

@Override 
public void create() {  
    batch = new SpriteBatch(); 

    player = new Texture(Gdx.files.internal("player.png")); 

    position = new Vector2((Gdx.graphics.getWidth()/2 - (player.getWidth()/2)),50);  
} 

@Override 
public void dispose() { 

} 

@Override 
public void render() { 
    Gdx.gl.glClearColor(1, 1, 1, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

    if(Gdx.input.isKeyPressed(Keys.W)) { 
     position.y += 1f; 
    } 
    if((Gdx.input.isKeyPressed(Keys.A)) && (position.x > 0)) { 
     position.x -= 2f; 
    } 
    if(Gdx.input.isKeyPressed(Keys.S)) { 
     position.y -= 1f; 
    } 
    if((Gdx.input.isKeyPressed(Keys.D)) && (position.x < Gdx.graphics.getWidth() - player.getWidth())) { 
     position.x += 2f; 
    } 

    if(Gdx.input.isTouched()) { 
     System.out.println("application clicked"); 
    } 

    if((Gdx.input.getAccelerometerX() >= 0) && (position.x > 0)) { 
     position.x -= 2f; 
    } 
    else if((Gdx.input.getAccelerometerX() < 0) && (position.x < Gdx.graphics.getWidth() - player.getWidth())) { 
     position.x += 2f; 
    } 

    System.out.println("Rotation: " + Gdx.input.getAccelerometerX()); 

    batch.begin(); 
    batch.draw(player, position.x, position.y); 
    batch.end(); 
} 

@Override 
public void resize(int width, int height) { 

} 

@Override 
public void pause() { 

} 

@Override 
public void resume() { 

} 
} 
+0

소스 코드를 덤핑과의 라인을 따라 뭔가 말은 stackoverflow.com에 대한 유용한 답변을 얻을 수있는 가장 좋은 방법이 아니다 "는이 할 수 있도록." http://stackoverflow.com/help/how-to-ask를보고 조금 다른 방식으로 질문을 골라 내고 싶을 수도 있습니다 ... –

+0

마치 비트 맵 폰트를 늘리고 비트 맵을 그릴 수 있습니다 . 그것의 매우 열심히 단지 google 그것. 그리고 yoi가 원하는 경우 비트 맵 글꼴을 사용하여 너비를 가져 와서 2로 나눈 다음 화면 너비의 절반에서 그 너비를 뺍니다. 예를 원하십니까? – vedi0boy

답변

5
float timeState=0f; 

public void render(){ 
// ............ 
timeState+=Gdx.graphics.getDeltaTime(); 
if(timeState>=1f){ 
// 1 second just passed 
    timeState=0f; // reset our timer 
    updateEverySecond(); // call the function that you want 
}