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