如果我使用精灵,我可以参考我的游戏WORLD UNITS设置精灵的大小和位置:
AtlasRegion region = textureAtlas.findRegion("0001");
sprite = new Sprite(region);
sprite.setPosition(11.5f, 5f);
sprite.setSize(7f, 7f * region.getRegionHeight() / region.getRegionWidth());
如何使用动画实现这一目标。如何设置每个关键帧精灵的大小?
textureAtlas = new TextureAtlas(Gdx.files.internal("data/bycicle.atlas"));
TextureRegion[] rotateUpFrames = new TextureRegion[4];
// Create an array of TextureRegions
rotateUpFrames[0] = (textureAtlas.findRegion("0001"));
rotateUpFrames[1] = (textureAtlas.findRegion("0002"));
rotateUpFrames[2] = (textureAtlas.findRegion("0003"));
rotateUpFrames[3] = (textureAtlas.findRegion("0004"));
rotateUpAnimation = new Animation(0.1f,rotateUpFrames);
答案 0 :(得分:0)
我设置了一个Animation子类,因此每次使用新区域更新精灵时,我都可以使用方便的方法来应用缩放。例如:
public class AnimationPlus extends Animation {
float scale;
public AnimationPlus (float frameDuration,
Array<? extends TextureRegion> keyFrames, PlayMode playMode, float scale)
{
super(frameDuration, keyFrames, playMode);
this.scale = scale;
}
public void applyKeyFrameToSprite (float stateTime, Sprite sprite)
{
TextureRegion region = getKeyFrame(stateTime);
sprite.setSize(scale,
scale * region.getRegionHeight() / region.getRegionWidth());
}
}
顺便说一句,如果你用动态字母的下划线命名动画帧(例如“bike_0”,“bike_1”,“bike_2”等),那么你可以方便地获得这样的区域数组:
Array<TextureRegion> bikeRegions = textureAtlas.findRegions("bike");
AnimationPlus animation = new AnimationPlus(0.1f, bikeRegions, PlayMode.LOOP, 7f);