그래서 나는 플레이어 내 게임에 내 코드를 리팩토링의 과정에있어 플레이어 클래스에서 그릴을 시도 할 때 이동 플레이어 클래스 시작되지 않습니다 난플레이어
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Player
{
protected String name;
protected float health, maxHealth;
protected Texture texture;
protected int xPos, yPos;
public Player(String name, float maxHealth, Texture texture) {
this(name, maxHealth, texture, 0, 0);
}
public Player(String name, float maxHealth, Texture texture, int xPos, int yPos) {
this.name = name;
this.health = this.maxHealth = maxHealth;
this.texture = texture;
this.xPos = xPos;
this.yPos = yPos;
}
public Texture getTexture() {
return this.texture;
}
public int getX() {
return xPos;
}
public int getY() {
return yPos;
}
public String getName() {
return name;
}
public void draw(SpriteBatch spriteBatch) {
spriteBatch.begin();
spriteBatch.draw(texture, xPos, yPos, 0.5f, 0.5f, 0, 0,
texture.getWidth(), texture.getHeight(), false, false);
spriteBatch.end();
}
public void update(float delta) {
processMovement(delta);
}
public void processMovement(float delta) {
if(Gdx.input.isKeyPressed(Input.Keys.A)) {
xPos -= 50 * delta;
}
if(Gdx.input.isKeyPressed(Input.Keys.D)) {
xPos += 50 * delta;
}
}
}
을 정사영 카메라를 사용하여, 다음에 할 일을 할 때 아직 지형을 추가하지 않았지만, 플레이어가 항상 중앙에 머물면서 플레이어가 그릴 때 지형을 돌아 다니게하고 싶습니다. 다음과 같이
내가 카메라를 만들어 내 플레이어를 그리기 위해이 코드는 다음과 같습니다
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class GameState implements Screen
{
private PixelGame parent;
private OrthographicCamera camera;
private Player player;
private Texture playerTexture;
private SpriteBatch spriteBatch;
public GameState(PixelGame parent) {
this.parent = parent;
this.playerTexture = new Texture(Gdx.files.internal("player/sprite.png"));
this.player = new Player("Me", 20, playerTexture);
this.spriteBatch = new SpriteBatch();
}
@Override
public void render(float delta) {
camera.update();
spriteBatch.setProjectionMatrix(camera.combined);
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
player.draw(spriteBatch);
player.update(delta);
}
@Override
public void show() {
}
@Override
public void dispose() {
}
@Override
public void resize(int width, int height) {
float ratio = (float)width/(float)height;
camera = new OrthographicCamera(2f * ratio, 2f);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
}
플레이어 스프라이트가 이동하지 않는 것,하지만 난 뭔가> 75 플레이어 스프라이트에 값을 변경할 때 스크린을 가로 질러 아무 것도없는 비즈니스처럼 펼쳐진다.