我不能为我的生活弄清楚为什么我设置相机位置(在create方法和更新方法中)都没有效果。
我已经检查过的主要课程正在调用更新。这是代码:
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();
}
}
我正试图让地图在启动时自动对角滚动...
答案 0 :(得分:0)
Menno Gouw回答了这个问题。他上面的评论指出我没有将相机的投影矩阵添加到spritebatch。
spriteBatch.setProjectionMatrix(camera.combined);
在begin()行之前的那一行是我需要解决的问题。