2
我是新來這個論壇,並註冊只是爲了問這個具體問題:我一直在關注視頻遊戲開發的YouTube網絡系列(如何製作2D遊戲 - 通過EddieVanHalen98),但他沒有告訴我如何讓相機跟隨一個特定的精靈。我如何讓相機跟隨播放器在LibGDX
我的渲染代碼是也遵循
public class [ClassName] {
polkymain game;
OrthographicCamera camera;
public static int PolkyX;
public static int PolkyY;
SpriteBatch batch;
public GameScreen(polkymain game){
this.game = game;
camera = new OrthographicCamera();
camera.setToOrtho(true, 1280, 1240);
batch = new SpriteBatch();
PolkyX = 0;
PolkyY = 0;
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.95F, 0.95F, 0.95F, 0.95F);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
generalUpdate();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(Assets.Sprite_Mario_main, PolkyX, PolkyY);
batch.end();
}
public void generalUpdate(){
if(Gdx.input.isKeyPressed(Keys.D) || (Gdx.input.isKeyPressed(Keys.LEFT))
{
PolkyX += 5;
}
if(Gdx.input.isKeyPressed(keys.A) || (Gdx.input.isKeyPressd(Keys.RIGHT))
{
PolkyX -= 5;
}
if(Gdx.input.isKeyPressed(keys.S) || (Gdx.input.isKeyPressd(Keys.DOWN))
{
PolkyY -= 5;
}
if(Gdx.input.isKeyPressed(keys.W) || (Gdx.input.isKeyPressd(Keys.UP))
{
PolkyY += 5;
}
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void show() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
,我有我的所有紋理和精靈編碼的「資產」類,不知道這是否是相關的,我不這麼認爲現在我想到它... 告訴我你是否也需要編碼。謝謝!
我已經格式化了您的代碼。您錯過了類聲明,因此請替換頂部的[ClassName]和其他您可能錯過的信息。 – krillgar