0
저는 libgdx를 처음 사용합니다. 화면에 볼을 렌더링하고 싶지만 볼 수있는 것은 검은 색 빈 화면입니다.libgdx - 내 렌더링을 볼 수 없습니다.
홈페이지
public class Main implements ApplicationListener
{
@Override
public void render()
{
if (!paused)
{
worldController.update(Gdx.graphics.getDeltaTime());
}
Gdx.gl.glClearColor(0, 0, 0, 0x255/255f);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
worldRenderer.render();
}
}
WorldRenderer
public class WorldRenderer implements Disposable
{
public void render()
{
batch.setProjectionMatrix(camera.combined);
batch.begin();
for (Ball b : getWorldController().balls)
b.render(batch);
batch.end();
}
}
볼
public class Ball extends AbstractGameObject
{
private TextureRegion textureRegion;
public Ball()
{
Texture texture = new Texture(Gdx.files.internal("images/ball.png"));
dimension.x = 1;
dimension.y = 1;
// Center image on game object
origin.set(dimension.x/2, dimension.y/2);
// Bounding box for collision detection
bounds.set(0, 0, dimension.x, dimension.y);
// Set physics values
terminalVelocity.set(3f, 4f);
friction.set(12f, 0f);
acceleration.set(0f, -25f);
position.x = 5;
position.y = 5;
textureRegion = new TextureRegion(texture, 0, 0, dimension.x, dimension.y);
}
@Override
public void render(SpriteBatch batch)
{
batch.draw(textureRegion,
position.x,
position.y,
origin.x,
origin.y,
dimension.x,
dimension.y,
scale.x,
scale.y,
rotation,
false);
}
}
추상 게임 개체 :
public abstract class AbstractGameObject
{
public Vector2 position;
public Vector2 dimension;
public Vector2 origin;
public Vector2 scale;
public float rotation;
public Vector2 velocity;
public Vector2 terminalVelocity;
public Vector2 friction;
public Vector2 acceleration;
public Rectangle bounds;
public AbstractGameObject()
{
this.position = new Vector2();
this.dimension = new Vector2();
this.origin = new Vector2();
this.scale = new Vector2();
this.velocity = new Vector2();
this.terminalVelocity = new Vector2();
this.friction = new Vector2();
this.acceleration = new Vector2();
this.bounds = new Rectangle();
}
public void updateMotionX(float deltaTime)
{
if (velocity.x != 0)
{
// Apply friction
if (velocity.x > 0)
{
velocity.x = Math.max(velocity.x - friction.x * deltaTime, 0);
}
else
{
velocity.x = Math.min(velocity.x + friction.x * deltaTime, 0);
}
}
// Apply acceleration
velocity.x += acceleration.x * deltaTime;
// Make sure that acceleration does not exceed the terminal velocity
velocity.x = MathUtils.clamp(velocity.x, -terminalVelocity.x, terminalVelocity.x);
}
public void updateMotionY(float deltaTime)
{
if (velocity.y != 0)
{
if (velocity.y > 0)
{
velocity.y = Math.max(velocity.y - friction.y * deltaTime, 0);
}
else
{
velocity.y = Math.min(velocity.y + friction.y * deltaTime, 0);
}
}
// Apply acceleration
velocity.y += acceleration.y * deltaTime;
// Make sure that acceleration does not exceed the terminal velocity
velocity.y = MathUtils.clamp(velocity.y, -terminalVelocity.y, terminalVelocity.y);
}
public void update(float deltaTime)
{
updateMotionX(deltaTime);
updateMotionY(deltaTime);
position.x += velocity.x * deltaTime;
position.y += velocity.y * deltaTime;
}
public abstract void render (SpriteBatch batch);
}
무엇이 없습니까? 내가 도대체 뭘 잘못하고있는 겁니까?
처음에는 코드가 누락되었습니다. 카메라 코드는 어디에 있습니까? – Chase
당신은 분명히 우리에게 당신의 카메라를 보여줄 필요가 있습니다. 그렇지 않으면 우리는 도울 수 없습니다. 작은 점 :'새로운 OrthographicCamera (80, 45) '를 사용하여 카메라를 만들면 새로운 카메라가 생성됩니다. 화면의 중간에 0,0 점, 너비는 80 단위, 신장. 따라서 볼의 반지름은 화면 너비의 1/80이됩니다. 1600 * 900 화면 (beautifull 번호를 가짐)에서 20px 반경을가집니다. – Springrbua