2013-12-10 5 views
1

좋아, 이건 어리석게 쉬운 일 이겠지만 어떤 이유 때문에 그냥 잡기가 쉽지가 않아.애니메이션의 전환 프레임

내가 서있는 애니메이션을 가지고 있고, 내가 원하는 것을 움직이는 애니메이션이 두 애니메이션 해당 증속 단일 프레임 전환을 재생하는 것입니다, 내가 달성하는 것 기운이 여기

아마도 내 코드입니다 (논리 값으로 그것을 시도) 누군가가 도울 수 있습니다.

또한 왼쪽/오른쪽을 향한 별도의 애니메이션을 수행합니다. 단일 애니메이션을 뒤집을 수있는 방법이 있습니까? 멍청한 놈 코더에서 미리

덕분에 - Heres는 일부 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); 


} 

답변

0

I는 무엇 상태를 사용하여 렌더링 할 애니메이션 처리 :

public static final int STATE_IDLE = 0; 
public static final int STATE_WALKINGLEFT = 1; 
public static final int STATE_WALKINGRIGHT = 2; 
public static final int STATE_TRANSITIONLEFT = 3; 
public static final int STATE_TRANSITIONRIGHT = 4; 

public int state = STATE_IDLE; 

그런 다음 상태를 전환 w로 변경합니다.

case Keys.A: 
case Keys.D: 
    velocity.x = 0; 
    state == STATE_IDLE; 
    animationTime = 0; 
: 만약 입력 유휴

if(animationTime>0.1F){ //your transition frame time 
    if(state == STATE_TRANSITIONLEFT){ 
     state = STATE_WALKINGLEFT; 
     animationTime = 0; 
    } 
    if(state == STATE_TRANSITIONRIGHT){ 
     state = STATE_WALKINGRIGHT; 
     animationTime = 0; 
    } 
} 

반환 상태 : 입력 i 번째 : 당신의 렌더링 방법에서

case Keys.A: 
    state = STATE_TRANSITIONLEFT; 
    velocity.x = -speed; 
    animationTime = 0; 
    break; 
case Keys.D: 
    state = STATE_TRANSITIONRIGHT; 
    velocity.x = speed; 
    animationTime = 0; 

, 몇 시간 동안 기다린 후 도보 상태로 전이 상태를 변경

마지막으로 현재 애니메이션을 렌더링합니다.

switch(state){ 
    case STATE_IDLE: 
     //draw idle animation 
     break; 
    case STATE_TRANSITIONLEFT: 
     //draw transitionleft frame 
     break; 
    case STATE_WALKINGLEFT: 
     //draw walkingleft animation 
     break; 
    //etc... 
} 

그리고 마지막 질문입니다. 그래, 당신은 당신의 애니메이션의 영역을 전환 할 수 있습니다 :

TextureRegion#flip

+0

Btw는 나머지 아름답게 일 – user2873364

관련 문제