【发布时间】:2016-06-05 09:48:33
【问题描述】:
我正在使用TexturepackgerGUI 将多个动画打包到一个精灵表中。我用Spriter 生成这些动画。 TexturepackerGUI 带有一个方便的功能,可以输出一个可用于偏移动画的偏移字段,因此当精灵变大时,它不会从左向右移动。
但是多个动画呢?当我从步行动画移动到空闲或运行时,它仍然会移动位置,因为这些帧使用更大的精灵,因为我在Spriter 中移动和旋转我的部件更多。
解决此问题的一种方法是在Spriter 中输出固定大小,但这会浪费大量纹理空间,因为我必须使用最大精灵的矩形大小。
这是我的包/atlas 文件的外观:
idle_cycle_heavy
rotate: false
xy: 1602, 2
size: 78, 95
orig: 124, 121
offset: 3, 20
index: 20
idle_cycle_heavy
rotate: false
xy: 1682, 2
size: 78, 95
orig: 124, 121
offset: 3, 20
index: 21
//...
run_cycle_heavy
rotate: false
xy: 162, 507
size: 78, 95
orig: 116, 113
offset: 22, 11
index: 25
run_cycle_heavy
rotate: false
xy: 1636, 406
size: 78, 97
orig: 116, 113
offset: 23, 13
index: 18
//...
这里我使用偏移量来绘制。
public void draw(SpriteBatch batch) {
TextureRegion currentFrame = getCurrentFrame();
if (currentFrame == null) Gdx.app.log("Unit.java", "Could not find proper frame.");
int posX = Math.round(((TextureAtlas.AtlasRegion) currentFrame).offsetX);
int posY = Math.round(((TextureAtlas.AtlasRegion) currentFrame).offsetY);
batch.draw(currentFrame, posX, posY);
}
/**
* Gets the texture region of the current frame taking the unit state into account
* @return the current TextureRegion
*/
private TextureRegion getCurrentFrame()
{
frameTime += Gdx.graphics.getDeltaTime();
if (unitState.equals(UnitState.Idle))
{
return idleAnimation.getKeyFrame(frameTime);
}
else if (unitState.equals(UnitState.Walking))
{
return walkAnimation.getKeyFrame(frameTime);
}
else if (unitState.equals(UnitState.Running))
{
return runAnimation.getKeyFrame(frameTime);
}
else if (unitState.equals(UnitState.Shooting))
{
return shootAnimation.getKeyFrame(frameTime);
}
return null;
}
我有点希望TexturePackerGui 中有一个选项可以让我根据最大的图像设置偏移量。
【问题讨论】:
标签: java animation libgdx sprite-sheet texturepacker