1
好吧,这将是一件愚蠢的事情,但由于某种原因,我只是没有抓住它。动画中的过渡帧
我有一个常设的动画,和移动的动画我想是玩其间的两个动画的单个帧过渡,我似乎无法完成它
这里是我的代码也许(与布尔试过)有人可以帮忙。
此外,我做单独的动画面对左/右,有没有一种方法,我可以只翻转单个动画?
感谢从一个小白编码器提前 - 我的继承人有一些irrelivent填充码切出
public class Player extends Sprite implements InputProcessor {
private Vector2 velocity = new Vector2();
private float speed = 60 * 2, gravity = 60 * 2.2f, animationTime = 0;
private boolean canJump;
private boolean attacking;
private boolean starting = true;
private Animation still, left, right, attack, start;
private TiledMapTileLayer collisionLayer;
public Player(Animation still, Animation left, Animation right, Animation attack, Animation start, TiledMapTileLayer collisionLayer) {
super(still.getKeyFrame(0));
this.still = still;
this.left = left;
this.right = right;
this.attack = attack;
this.start = start;
this.collisionLayer = collisionLayer;
setSize(getWidth(), getHeight() /* * 1.5f*/);
//setScale((float) 1.4);
}
@Override
public void draw(SpriteBatch spriteBatch) {
update(Gdx.graphics.getDeltaTime());
super.draw(spriteBatch);
// update animation
animationTime += delta;
setRegion(
velocity.x < 0 ? left.getKeyFrame(animationTime) :
velocity.x > 0 ? right.getKeyFrame(animationTime) :
attacking == true ? attack.getKeyFrame(animationTime) :
still.getKeyFrame(animationTime));
}
@Override
public boolean keyDown(int keycode) {
switch(keycode) {
case Keys.W:
if(canJump) {
velocity.y = speed/1.8f;
canJump = false;
}
break;
case Keys.A:
velocity.x = -speed;
animationTime = 0;
break;
case Keys.D:
velocity.x = speed;
animationTime = 0;
case Keys.I:
attacking = true;
animationTime = 0.15f;
}
return true;
}
@Override
public boolean keyUp(int keycode) {
switch(keycode) {
case Keys.A:
case Keys.D:
velocity.x = 0;
animationTime = 0;
case Keys.I:
animationTime = 0;
attacking = false;
}
return true;
}
而且从我的屏幕让它在地图上
@Override
public void show() {
map = new TmxMapLoader().load("maps/map.tmx");
camera = new OrthographicCamera();
batch = new SpriteBatch();
backimage = new Sprite(new Texture("images/backgrounds/background.png"));
playerAtlas = new TextureAtlas("img/player/player.pack");
Animation still, left, right, attack, start;
still = new Animation(2/2f, playerAtlas.findRegions("still"));
left = new Animation(1/6f, playerAtlas.findRegions("left"));
right = new Animation(2/26f, playerAtlas.findRegions("right"));
attack = new Animation(1/6f, playerAtlas.findRegions("attack"));
start = new Animation(1/2f, playerAtlas.findRegions("start"));
still.setPlayMode(Animation.LOOP);
left.setPlayMode(Animation.LOOP);
right.setPlayMode(Animation.LOOP);
start.setPlayMode(Animation.NORMAL);
attack.setPlayMode(Animation.NORMAL);
player = new Player(still, left, right, attack, start, (TiledMapTileLayer) map.getLayers().get(0));
MapLayer layer = map.getLayers().get("objects");
for(MapObject object : layer.getObjects())
if(object.getName().equals("playerstart"))
player.setPosition(object.getProperties().get("x", Integer.class), object.getProperties().get("y", Integer.class));
Gdx.input.setInputProcessor(player);
}
顺便说一句,其余工作精美 – user2873364