0
我不能爲我的生活找出爲什麼我設置相機位置(無論是在創建方法和更新方法)沒有效果。Libgdx相機 - 設置位置沒有效果
更新被我的主要類調用,我已經檢查過。這裏是代碼:
package com.moneylife.zombietown;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class GameManager {
SpriteBatch spriteBatch;
float deltaTime;
Texture mapTexture;
OrthographicCamera camera;
int WORLDWIDTH = 2880, WORLDHEIGHT = 1920;
public GameManager(){
spriteBatch = new SpriteBatch();
mapTexture = new Texture("map2880x1920.jpg");
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera(940, 940 * (h/w)); /// POSSIBLY NEED TO CHECK THIS *******
camera.position.set(camera.viewportWidth/2 + 500, camera.viewportHeight/2, 0);
camera.update();
}
public void update(){
deltaTime = Gdx.graphics.getDeltaTime();
camera.position.x += 10;
camera.position.y += 10;
camera.update();
}
public void draw(){
spriteBatch.begin();
spriteBatch.draw(mapTexture,0,0);
spriteBatch.end();
}
}
,這裏是主類,以防萬一,這是相關的:
package com.moneylife.zombietown;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class ZombieTown extends ApplicationAdapter {
GameManager gameManager;
@Override
public void create() {
gameManager = new GameManager();
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
gameManager.update();
gameManager.draw();
}
@Override
public void dispose() {
gameManager.spriteBatch.dispose();
}
}
我只是想使地圖自動啓動時,現在是斜向滾動...
您需要將相機的投影矩陣加到您正在繪製的精靈批處理中。 '.begin'前的'batch.setProjectionMatrix(cam.combined)'。現在在電話上,所以不能幫助更多的atm。 – Madmenyo
絕對英雄!所有的幫助都很讚賞。再次感謝。我希望你把這個作爲完整的答案,所以我可以勾選它。 – Ronny
我會在我看的足球比賽的一半時間;) – Madmenyo