2016-09-07 4 views
1

현재 소행성을 피해야하는 게임을 프로그래밍하고 있습니다. 엉망인 좌표를 처리해야했고 스프라이트의 좌표를 추측해야했습니다. 나는 이제 내 세계를 묘사하는 임의의 단위를 가지고있다. 불행히도 게임 화면이 제대로 작동하지 않습니다. 소행성을 렌더링하려고 할 때 게임 화면에 검은 색 화면이 표시됩니다.GameScreen이 검은 색 화면을 표시합니다.

public class GameScreen extends Screen { 

private OrthographicCamera cam; 
private Spaceship spaceship; 
private Asteroids asteroids; 
private Background bg; 



@Override 
public void create() { 
    // TODO Auto-generated method stub 

    bg = new Background(); 
    spaceship = new Spaceship(); 
    asteroids = new Asteroids(); 

    float aspectratio = 16/10; 

    cam = new OrthographicCamera(100, 100 * aspectratio); 

    cam.position.set(cam.viewportWidth/2f, cam.viewportHeight/2f, 0); 

    cam.update(); 

    } 



@Override 
public void render(SpriteBatch batch) { 
    // TODO Auto-generated method stub 

    cam.update(); 
    batch.setProjectionMatrix(cam.combined); 

    batch.begin(); 
    bg.render(batch); 
    spaceship.render(batch); 
    batch.end(); 

} 

표시 된 위의 코드는 잘 작동이 저를 보여줍니다 나는 GameScreen 클래스의 소행성의 렌더링 방법을 추가 할 때

enter image description here

가 GameScreen 그냥 검은 색 :

@Override 
    public void render(SpriteBatch batch) { 
    // TODO Auto-generated method stub 

    cam.update(); 
    batch.setProjectionMatrix(cam.combined); 

    batch.begin(); 
    bg.render(batch); 
    spaceship.render(batch); 
    batch.end(); 

    } 

개 소행성 클래스 :

public class Asteroid { 

private Vector2 p; 
private Vector2 v; 

private float mass; 
private float radius; 

public final float maxV = 200; 
public final float minV = 50; 

public final float rMin = 10; 
public final float rMax = 30; 

public final float minX = MyGdxGame.WIDTH; 
public final float minY = MyGdxGame.HEIGHT;; 

float alpha = MathUtils.random(0, 360); 

public Asteroid(float maxX, float maxY, List<Asteroid> asteroids) { 

    do { 

    radius = MathUtils.random(rMin, rMax); 
    masse = radius * radius * radius; 

    float alpha = MathUtils.random(0, 360); 

    p = new Vector2(MathUtils.random(minX, maxX), MathUtils.random(minY, 
      maxY)); 

    float vBetrag = MathUtils.random(minV, maxV); 

    v = new Vector2(vBetrag * MathUtils.cosDeg(alpha), 
      vBetrag * MathUtils.cosDeg(alpha)); 
    } while (ueberlappMit(asteroids)); 

} 

private boolean ueberlappMit(List<Asteroid> asteroids) { 

    for(Asteroid a: asteroids){ 
     if(abstand(a) < radius + a.radius + 10){ //! 
      return true; 
     } 
    } 

    return false; 

} 

public void update(float deltaT, float xMin, float xMax, float yMin, float yMax) { 
    p.x += v.x * deltaT; 
    p.y += v.y * deltaT; 

    while(p.x > xMax) 
    { 
     p.x -= (xMax - xMin); 
    } 
    while(p.x < xMin) 
    { 
     p.x += (xMax - xMin); 
    } 
    while(p.y > yMax) 
    { 
     p.y -= (yMax - yMin); 
    } 
    while(p.y < yMin) 
    { 
     p.y += (yMax - yMin); 
    } 
} 


public float abstand(Asteroid a2) { 

    return p.dst(a2.p); 

} 

소행성 클래스 : 당신의 도움들 주셔서

public class Asteroids extends Entity { 

private final int numberofAsteroids = 150; 
private float xMin, xMax, yMin, yMax; 
private List<Asteroid> asteroids = new ArrayList<Asteroid>(); 

private final int cyclicBoundaryConditionsMultiple = 2; 

public Asteroids() { 


    xMin = MyGdxGame.WIDTH * (-cyclicBoundaryConditionsMultiple); 
    xMax = MyGdxGame.WIDTH * (cyclicBoundaryConditionsMultiple); 
    yMin = MyGdxGame.HEIGHT * (-cyclicBoundaryConditionsMultiple); 
    yMax = MyGdxGame.HEIGHT * (cyclicBoundaryConditionsMultiple); 


    for (int i = 0; i < anzahl; i++) { 
     Asteroid a = new Asteroid(xMax, yMax, asteroids); 
     asteroids.add(a); 
    } 

} 

@Override 
public void update() { 

    for (Asteroid a : asteroids) { 
     a.update(Gdx.graphics.getDeltaTime(), xMin, xMax, yMin, yMax); 
    } 

    for (int i = 0; i < numberofAsteroids; i++) { 

     Asteroid a1 = asteroids.get(i); 

     for (int j = i + 1; j < anzahl; j++) { 

      Asteroid a2 = asteroids.get(j); 

      float abstand = a1.abstand(a2); 

      if (abstand < a1.getRadius() + a2.getRadius()) { 

       calculateCollision(a1, a2); 

      } 

     } 

    } 

} 


} 

@Override 
public void render(ShapeRenderer renderer) { 

    for (Asteroid a : asteroids) { 

     System.out.println("RENDER A"); 

     renderer.setColor(0, 0, 0, 1); 
     renderer.circle(a.getP().x, a.getP().y, a.getRadius()); 

    } 

    } 
+0

내 로그 캣는 말한다 : 09-07 16 : 58 : 53.269 : I/타임 라인 (24341) : 타임 라인 : Activity_idle ID : [email protected] 시간 : 5,449,248 09-07 16 : 58 : 59.776 : I/AndroidInput (24341) : 센서 리스너가 찢어졌습니다. –

+0

.render 코드를 알려주십시오. –

+0

@JonathanBotha 렌더링 방법은 하단의 Asteriods Clss에 있습니다. BG는 단지 배경을 렌더링하고 소행성이 없으면 잘 작동합니다. –

답변

0

들으 많이, 내가 문제를 해결했다. private boolean ueberlappMit (List asteroids) 메서드는 소행성이 겹칠 지 여부와 소행성이 다시 생성되는지 여부를 확인합니다. 문제는 너무 높은 반경을 선택하면 게임이 소행성 클래스의 do while 루프에 달라 붙었다는 것입니다.

관련 문제