2016-09-14 2 views
1

나는 간단한 게임을 개발 중이며 문제에 직면 해있다. 게임 세계 해상도보다 낮은 화면 해상도를 가진 장치에서 움직임이 부드럽 지 않고 매우 역 겹게 보입니다.libgdx 부드럽게 움직이지 않는 작은 화면 해상도

내 코드 :

public float LAST_GROUND_LEVEL, CURRENT_GROUND_LEVEL, LAST_GROUND_LEVEL_PLANKS; 
public int CURRENT_GROUND_INDEX, COUNTER_TO_NEXT_PLANK = 0; 

private Ball ball; 
private Array<Plank> planks; 
private Array<GroundPlank> groundPlanks; 

private Random random; 

public PlayState(GameStateManager gsm) { 
    super(gsm); 
    orthographicCamera.setToOrtho(false, JumpingBall.WIDTH, JumpingBall.HEIGHT); 
    ball = new Ball(JumpingBall.WIDTH/2, JumpingBall.HEIGHT/2, gameStateManager); 

    planks = new Array<Plank>(); 

    random = new Random(); 
    groundPlanks = new Array<GroundPlank>(); 
    for (int i = 0; i < 3; i++) { 
     if (i != 2) { 
      groundPlanks.add(new GroundPlank(i * orthographicCamera.viewportWidth/2, 600 * JumpingBall.RATIO, orthographicCamera)); 
      CURRENT_GROUND_INDEX = i; 
      CURRENT_GROUND_LEVEL = 600 * JumpingBall.RATIO; 
     } else { 
      boolean side = random.nextBoolean(); 
      if (side == true) { 
       groundPlanks.add(new GroundPlank(i * orthographicCamera.viewportWidth/2, 800 * JumpingBall.RATIO, orthographicCamera)); 
       LAST_GROUND_LEVEL = 800 * JumpingBall.RATIO; 
      } else { 
       groundPlanks.add(new GroundPlank(i * orthographicCamera.viewportWidth/2, 400 * JumpingBall.RATIO, orthographicCamera)); 
       LAST_GROUND_LEVEL = 400 * JumpingBall.RATIO; 
      } 
     } 
     LAST_GROUND_LEVEL_PLANKS = LAST_GROUND_LEVEL; 
     COUNTER_TO_NEXT_PLANK++; 
    } 
} 

@Override 
public void handleInput() { 
    if (Gdx.input.justTouched()) { 
     ball.jump(); 
    } 
} 

@Override 
public void update(float delta) { 
    if (delta > 0f) { 
     handleInput(); 
     for (int i = 0; i < groundPlanks.size; i++) { 
      if ((ball.getPosition().x + ball.getBall().getWidth()/30 * JumpingBall.RATIO/2 > groundPlanks.get(i).getPosition().x) &(ball.getPosition().x + ball.getBall().getWidth()/30 * JumpingBall.RATIO/2 < groundPlanks.get(i).getPosition().x + orthographicCamera.viewportWidth/2)) 
      { 
       ball.update(delta, CURRENT_GROUND_LEVEL + groundPlanks.get(0).getGroundPlankTexture().getHeight()/4 * JumpingBall.RATIO, groundPlanks.get(i).getPosition().x + orthographicCamera.viewportWidth/2, CURRENT_GROUND_LEVEL + groundPlanks.get(0).getGroundPlankTexture().getHeight()/4 * JumpingBall.RATIO, LAST_GROUND_LEVEL + groundPlanks.get(0).getGroundPlankTexture().getHeight()/4 * JumpingBall.RATIO); 
      } 
     } 
     orthographicCamera.position.x = ball.getPosition().x + ball.getBall().getWidth()/30 * JumpingBall.RATIO/2; 

     boolean foundPlank = false; 
     for (int i = 0; i < groundPlanks.size; i++) { 
      if (foundPlank == false) { 
       GroundPlank groundPlank = groundPlanks.get(i); 
       GroundPlank RepositionPlank; 

       if ((orthographicCamera.position.x > groundPlank.getPosition().x) & ((groundPlank.getPosition().x + orthographicCamera.viewportWidth/2) > orthographicCamera.position.x)) { 
        CURRENT_GROUND_LEVEL = groundPlank.getPosition().y; 
        if (i > 1) { 
         RepositionPlank = groundPlanks.get(0); 
        } else if (i == 1) { 
         RepositionPlank = groundPlanks.get(2); 
        } else { 
         RepositionPlank = groundPlanks.get(1); 
        } 
        if (i != CURRENT_GROUND_INDEX) { 
         boolean side = random.nextBoolean(); 
         if (side == true) { 
          if (LAST_GROUND_LEVEL < GroundPlank.HIGHEST_OPENING) { 
           RepositionPlank.Reposition(groundPlank.getPosition().x + orthographicCamera.viewportWidth/2, LAST_GROUND_LEVEL + 200 * JumpingBall.RATIO); 
           LAST_GROUND_LEVEL = LAST_GROUND_LEVEL + 200 * JumpingBall.RATIO; 
          } else { 
           RepositionPlank.Reposition(groundPlank.getPosition().x + orthographicCamera.viewportWidth/2, LAST_GROUND_LEVEL - 200 * JumpingBall.RATIO); 
           LAST_GROUND_LEVEL = LAST_GROUND_LEVEL - 200 * JumpingBall.RATIO; 
          } 
         } else { 
          if (LAST_GROUND_LEVEL > GroundPlank.LOWEST_OPENING) { 
           RepositionPlank.Reposition(groundPlank.getPosition().x + orthographicCamera.viewportWidth/2, LAST_GROUND_LEVEL - 200 * JumpingBall.RATIO); 
           LAST_GROUND_LEVEL = LAST_GROUND_LEVEL - 200 * JumpingBall.RATIO; 
          } else { 
           RepositionPlank.Reposition(groundPlank.getPosition().x + orthographicCamera.viewportWidth/2, LAST_GROUND_LEVEL + 200 * JumpingBall.RATIO); 
           LAST_GROUND_LEVEL = LAST_GROUND_LEVEL + 200 * JumpingBall.RATIO; 
          } 
         } 
         CURRENT_GROUND_INDEX = i; 

         for (int j = 0; j < groundPlanks.size; j++) { 
          if (orthographicCamera.position.x < groundPlanks.get(j).getPosition().x) { 
           LAST_GROUND_LEVEL_PLANKS = groundPlanks.get(j).getPosition().y; 
          } 
         } 

         COUNTER_TO_NEXT_PLANK++; 
         if (COUNTER_TO_NEXT_PLANK == 4) { 
          if (planks.size != 0) { 
           Plank plank = planks.get(0); 
           plank.reposition(RepositionPlank.getPosition().x, LAST_GROUND_LEVEL_PLANKS + 20 * JumpingBall.RATIO + RepositionPlank.getGroundPlankTexture().getHeight()/4 * JumpingBall.RATIO, RepositionPlank.getGroundPlankTexture().getHeight()/4 * JumpingBall.RATIO + LAST_GROUND_LEVEL_PLANKS + 150 * JumpingBall.RATIO); 
          } else { 
           planks.add(new Plank(RepositionPlank.getPosition().x, LAST_GROUND_LEVEL_PLANKS + 20 * JumpingBall.RATIO + RepositionPlank.getGroundPlankTexture().getHeight()/4 * JumpingBall.RATIO, RepositionPlank.getGroundPlankTexture().getHeight()/4 * JumpingBall.RATIO + LAST_GROUND_LEVEL_PLANKS + 150 * JumpingBall.RATIO)); 
          } 
          COUNTER_TO_NEXT_PLANK = 0; 
         } 
        } 
        foundPlank = true; 
       } 
      } 
     } 

     if (planks.size != 0){ 
      if (planks.get(0).Collides(ball.getBounds())){ 
       gameStateManager.set(new MenuState(gameStateManager)); 
      } 
     } 
    } 
    orthographicCamera.update(); 
} 

@Override 
public void render(SpriteBatch spriteBatch) { 
    spriteBatch.setProjectionMatrix(orthographicCamera.combined); 
    spriteBatch.begin(); 
    spriteBatch.draw(ball.getBall(), ball.getPosition().x, ball.getPosition().y, ball.getBall().getWidth()/30 * JumpingBall.RATIO, ball.getBall().getHeight()/30 * JumpingBall.RATIO); 
    for (Plank plank : planks) { 
     spriteBatch.draw(plank.getPlank(), plank.getPosTopPlank().x, plank.getPosTopPlank().y, plank.getPlank().getWidth() * JumpingBall.RATIO/4, plank.getPlank().getHeight() * JumpingBall.RATIO); 
     spriteBatch.draw(plank.getPlank(), plank.getPosBotPlank().x, plank.getPosBotPlank().y, plank.getPlank().getWidth() * JumpingBall.RATIO/4, plank.getPlank().getHeight() * JumpingBall.RATIO); 
    } 
    for (GroundPlank groundPlank : groundPlanks) { 
     spriteBatch.draw(groundPlank.getGroundPlankTexture(), groundPlank.getPosition().x, groundPlank.getPosition().y, orthographicCamera.viewportWidth/2, groundPlank.getGroundPlankTexture().getHeight() * JumpingBall.RATIO/4); 
    } 
    spriteBatch.end(); 
} 


@Override 
public void dispose() { 
    for (Plank plank : planks) { 
     plank.dispose(); 
    } 
    ball.getBall().dispose(); 
    for (GroundPlank groundPlank : groundPlanks) { 
     groundPlank.getGroundPlankTexture().dispose(); 
    } 
} 

편집 :

public void update(float delta, float groundlevel, float cur_x_end, float cur_y, float next_y){ 
    GROUND_LEVEL = groundlevel; 
    if (position.y > GROUND_LEVEL){ 
     velocity.add(0, GRAVITY, 0); 
    } 
    velocity.scl(delta); 
    position.add(MOVEMENT * delta, velocity.y, 0); 
    if ((position.y <= GROUND_LEVEL) & (position.x + getBall().getWidth()/30 * JumpingBall.RATIO < cur_x_end)){ 
     if (Down == false) { 
      position.y = GROUND_LEVEL; 
     } 
    } else if (position.x + getBall().getWidth()/30 * JumpingBall.RATIO > cur_x_end){ 
     if (next_y > cur_y){ 
      if (position.y < next_y){ 
       Down = true; 
      } 
     } 
    } 
    if (position.y + getBall().getHeight()/30 * JumpingBall.RATIO < 0){ 
     gameStateManager.set(new MenuState(gameStateManager)); 
    } 
    if (position.y >= JumpingBall.WORLD_HEIGHT * JumpingBall.RATIO - BallTexture.getHeight()/30 * JumpingBall.RATIO){ 
     position.y = JumpingBall.WORLD_HEIGHT * JumpingBall.RATIO - BallTexture.getHeight()/30 * JumpingBall.RATIO; 
    } 
    velocity.scl(1/delta); 
    bounds.setPosition(position.x, position.y); 
} 
+0

프레임 율 문제입니까? '역겨운'이란 무엇을 의미합니까? Ball 클래스에서 업데이트 메서드를 게시 할 수 있습니까? –

+0

게시물을 업데이트했습니다. 진절머리 나는 말은 텍스처가 흔들리는 것을 의미합니다. fps가 항상> 56이기 때문에 프레임 속도 문제가 아닙니다. –

답변

-1

평균적으로 고르지 않은 픽셀로 볼을 움직일 수 있습니다. 평균 속도가 1.6 픽셀 인 경우 이동합니다. 프레임에서 볼은 1 픽셀을 약간의 프레임 이동하고 2 픽셀은 다른 프레임을 이동합니다. 이것은 말더듬을 초래할 것입니다.

반 화소가 없으므로 공이 각 프레임마다 동일한 수의 픽셀을 이동하도록 속도를 조정해야합니다.

+0

고마워요! 그것은 나를 많이 도왔다! –

관련 문제