이전에 각 상태에 대해 별도의 .png 및 textureAtlas 파일을 사용하여 스프라이트의 여러 상태 (정지/보행/점프)에 애니메이션을 적용하고있었습니다. 그것은 잘 작동했다. 이제 저는이 별개의 시트를 하나의 PNG로 합치고 하나의 .pack
파일을 생성했습니다. 이제는 지역별로 이러한 상태에 액세스 할 수 있지만 더 이상 움직이지 않습니다. 전체 애니메이션이 아닌 각 상태의 첫 번째 스프라이트 만 그려집니다. 단일 스프라이트 시트를 사용하여 스프라이트 애니메이션하기
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
public class MyGdxGame extends ApplicationAdapter implements InputProcessor {
private SpriteBatch batch;
private TextureAtlas textureAtlas;
private TextureAtlas textureAtlas2;
private Animation animation;
private Animation animation2;
private Animation currentAnimation;
private float elapsedTime = 0;
@Override
public void create() {
batch = new SpriteBatch();
textureAtlas = new TextureAtlas(Gdx.files.internal("Wolverine.txt"));
animation = new Animation(1/7f, textureAtlas.findRegion("Standing"));
animation2 = new Animation(1/7f, textureAtlas.findRegion("Walking"));
currentAnimation = animation;
Gdx.input.setInputProcessor(this);
}
@Override
public void dispose() {
batch.dispose();
textureAtlas.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
//sprite.draw(batch);
elapsedTime += Gdx.graphics.getDeltaTime();
batch.draw(currentAnimation.getKeyFrame(elapsedTime, true), 0, 0);
batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.LEFT) {
currentAnimation = animation2;
}
return true;
}
@Override
public boolean keyUp(int keycode) {
return false;
}
@Override
public boolean keyTyped(char character) {
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
}
이
는 문제는 당신이Animation
생성자 하나 개의 애니메이션 프레임을 제공하고 있다는 점이다 나는 spritesheet
Wolverine.png
size: 256, 256
format: RGBA8888
filter: Linear,Linear
repeat: none
Standing
rotate: false
xy: 0, 0
size: 64, 64
orig: 64, 64
offset: 0, 0
index: 1
Standing
rotate: false
xy: 64, 0
size: 64, 64
orig: 64, 64
offset: 0, 0
index: 2
Standing
rotate: false
xy: 128, 0
size: 64, 64
orig: 64, 64
offset: 0, 0
index: 3
Walking
rotate: false
xy: 192, 0
size: 64, 64
orig: 64, 64
offset: 0, 0
index: 1
Walking
rotate: false
xy: 0, 64
size: 64, 64
orig: 64, 64
offset: 0, 0
index: 2
Walking
rotate: false
xy: 64, 64
size: 64, 64
orig: 64, 64
offset: 0, 0
index: 3
Walking
rotate: false
xy: 128, 64
size: 64, 64
orig: 64, 64
offset: 0, 0
index: 4
Walking
rotate: false
xy: 192, 64
size: 64, 64
orig: 64, 64
offset: 0, 0
index: 5
Walking
rotate: false
xy: 0, 128
size: 64, 64
orig: 64, 64
offset: 0, 0
index: 6
당신의'.pack' 파일 내용을 첨부 해주세요 –
좋아, 원래 게시물에 spritesheet에 사용하고있는 데이터 파일을 추가했습니다. –