我一直在尝试找出最好的方法,用一些使用textureatlas的东西来替换这段代码,而不是将纹理分割成不同的区域。使用它会更容易吗?
private void loadAllAnimations(){
// Walking animation
Texture texture = Utility.getTextureAsset(characterSpritePath); // Gets default.png
TextureAtlas atlas = Utility.getAtlas(characterAtlasPath); Gets default.atlas
TextureRegion[][] textureFrames = TextureRegion.split(texture, FRAME_WIDTH, FRAME_HEIGHT);
walkDownFrames = new Array<TextureRegion>(3);
walkLeftFrames = new Array<TextureRegion>(3);
walkRightFrames = new Array<TextureRegion>(3);
walkUpFrames = new Array<TextureRegion>(3);
for (int i = 0; i < 4; i++){
for (int j = 0; j < 3; j++){
TextureRegion region = textureFrames[i][j];
if (region == null){
Gdx.app.debug(TAG, "Got null animation frame " + i + "," + j);
}
switch (i){
case 0:
walkDownFrames.insert(j, region);
break;
case 1:
walkLeftFrames.insert(j, region);
break;
case 2:
walkRightFrames.insert(j, region);
break;
case 3:
walkUpFrames.insert(j, region);
break;
}
}
}
walkDownAnimation = new Animation<>(0.25f, walkDownFrames, Animation.PlayMode.LOOP);
walkLeftAnimation = new Animation<>(0.25f, walkDownFrames, Animation.PlayMode.LOOP);
walkRightAnimation = new Animation<>(0.25f, walkRightFrames, Animation.PlayMode.LOOP);
walkUpAnimation = new Animation<>(0.25f, walkUpFrames, Animation.PlayMode.LOOP);
}
这是Map册和图片
Map集:
DefaultDood.png
size: 512,64
format: RGBA8888
filter: Nearest,Nearest
repeat: none
DefaltManBack
rotate: false
xy: 342, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManBackWalkin1
rotate: false
xy: 138, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManBackWalkin2
rotate: false
xy: 36, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManForwardWalkin1
rotate: false
xy: 2, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManForwardWalkin2
rotate: false
xy: 206, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManFront
rotate: false
xy: 376, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManLeftStill
rotate: false
xy: 240, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManLeftWalkin1
rotate: false
xy: 70, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManLeftWalkin2
rotate: false
xy: 274, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManRightWalkin1
rotate: false
xy: 308, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManRightWalkin2
rotate: false
xy: 172, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
DefaltManSideRightStill
rotate: false
xy: 104, 2
size: 32, 32
orig: 32, 32
offset: 0, 0
index: -1
精灵表:图像
如果有什么事情我搞砸了或者很容易解决,我会喜欢的(我还使用了精通libgdx游戏开发的书来指导做什么)。谢谢您!
1条答案
按热度按时间oaxa6hgo1#
在原始纹理图像文件中,在帧编号前加下划线。例如
defaltmanbackalkin\ u 1.png文件
defaltmanbackalkin\ u 2.png文件
defaltmanbackalkin\ u 3.png文件
defaltmanbackalkin_4.png文件
等。
然后可以从atlas中获取整个列表作为数组传递给动画构造函数: