我试图在Libgdx中制作等距视频游戏,当我编写动画时,我有一个奇怪的错误。
我在场景中有两个3个图块:没有动画的静态体,瓷砖地板和带动画的正文。
所有都具有相同的坐标,静态的身体没有动画和瓷砖地板处于相同的位置,但带有动画的身体处于错误的位置。
此处图像中的所有图像同时位于同一场景中:
静态正文是动画的Spritesheet中的一个框架。
以下是我的相关代码:
TextureAtlas texureAtlasHair;
Animation<TextureRegion> animationHairHeroRunning;
SpriteBatch batch;
texureAtlasHair = new TextureAtlas("hero/ClothesBueno/ClothesB.atlas");
animationHairHeroRunning = new Animation<TextureRegion>(1f/4f,texureAtlasHair.findRegions("Stance"));
heroLoad = new Texture("map/Stance_1.png");
heroLoadSprite = new Sprite(heroLoad);
heroLoadSprite.flip(false,true);
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(dungeonCam.combined);
dungeonCam.update();
batch.begin();
elapsedTime += Gdx.graphics.getDeltaTime();
//FloorTile
Vector2 pointFloor = twoDToIso(new Vector2(25,30));
batch.draw(floor,pointFloor.x,pointFloor.y);
//Hero without animation
Vector2 pointHero = twoDToIso(new Vector2(25,30));
batch.draw(heroLoadSprite,pointHero.x,pointHero.y);
//Hero with animation
TextureRegion currentFrameHair =
animationHairHeroRunning.getKeyFrame(elapsedTime,true);
batch.draw(currentFrameHair,pointHero.x,pointHero.y,128,-128);
batch.end();
}
public Vector2 twoDToIso(Vector2 punto) {
Vector2 tempP = new Vector2(0, 0);
tempP.x = (punto.x - punto.y) * 32;
tempP.y = (punto.x + punto.y) * 16;
return tempP;
}
修改
我的.atlas是这样的。
我的实际代码是AtlasRegions:
Array<TextureAtlas.AtlasRegion> arrayRegions;
texureAtlasHair = new TextureAtlas("hero/ClothesBueno/ClothesB.atlas");
arrayRegions = texureAtlasHair.findRegions("Stance");
animationHairHeroRunning = new Animation(1f/4f,arrayRegions);