2016-06-01 5 views
0

이미 텍스처 영역 그리기가 완료되었지만 텍스처 영역을 뒤집으려고 할 때 작동하지 않고 여러 프레임을 그릴 때도 작동하지 않습니다. 내가 가져 오기 프레임 방법 내 몸의 속도를 확인하려하지만이 코드를 사용할 때 나에게 공을 준다 :Libgdx 텍스처 영역이 바뀌지 않습니다

Gdx.app.log(String.valueOf(b2body.getLinearVelocity().x),"hi"); 

이 사람이 나를 도울 수 있습니다.

public class Collector extends Sprite { 
    public enum State{STANDING,RUNNING,DEAD}; 
    public State currentState; 
    public State previousState; 
    public World world; 
    public Body b2body; 
    private TextureRegion collectorStand; 
    private Animation collectorRun; 
    private float stateTimer; 
    private boolean runningRight; 

    public Collector(World world,PlayScreen screen) 
    { 
     super(screen.getAtlas().findRegion("myboy1")); 
     this.world=world; 
     currentState=State.STANDING; 
     previousState=State.STANDING; 
     stateTimer=0; 
     runningRight=true; 
     Array<TextureRegion> frames=new Array<TextureRegion>(); 
     for(int i=0;i<3;i++) 
     frames.add(new TextureRegion(getTexture(),i*90,122,90,300)); 
     //frames.add(new TextureRegion(getTexture(),90,122,110,300)); 
     //frames.add(new TextureRegion(getTexture(),200,122,110,300)); 

     collectorRun=new Animation(0.1f,frames); 
     frames.clear(); 


     collectorStand=new TextureRegion(getTexture(), 0, 122, 89, 300); 
     //collectorStand=new TextureRegion(getTexture(),90,122,110,300); 
     //collectorStand=new TextureRegion(getTexture(),200,122,110,300); 
     defineCollector(); 
     setBounds(0,0,50/Fruits.PPM,100/Fruits.PPM);//here we can change the size of our Animation 


     setRegion(collectorStand); 
    } 
    public TextureRegion myregion(float dt) 
    { 
     TextureRegion region; 
     region=collectorStand; 

     Gdx.app.log(String.valueOf(b2body.getLinearVelocity().x),"hi"); 
     if(b2body.getLinearVelocity().x<0) 
     { 
      region.flip(true,false); 
     } 

     return region; 
    } 
    public void update(float dt) 
    { 
     setPosition(b2body.getPosition().x - getWidth()/2, b2body.getPosition().y - getHeight()/2.8f); 
     //setRegion(myregion(dt)); 
     setRegion(getFrame(dt)); 
    } 
    public TextureRegion getFrame(float dt)// return the appropriate frames for the sprite to be drawn 
    { 
     currentState=getState(); 
     TextureRegion region; 
     switch (currentState) 
     { 
      case RUNNING: 
       region=collectorRun.getKeyFrame(stateTimer,true); 
       break; 
      case STANDING: 
      default: 
       region=collectorStand; 
       break; 
     } 
     Gdx.app.log(String.valueOf(b2body.getLinearVelocity().x),"hi"); 
     if((b2body.getLinearVelocity().x<0 || !runningRight)&& !region.isFlipX()) 
     { 
      region.flip(true,false); 
      runningRight=false; 
     } 
     else if((b2body.getLinearVelocity().x>0 || runningRight)&& region.isFlipX()) 
     { 
      region.flip(true,false); 
      runningRight=true; 
     } 
     stateTimer=currentState==previousState?stateTimer+dt:0; 
     previousState=currentState; 
     return region; 
    } 
    public State getState() 
    { 
     if(b2body.getLinearVelocity().x!=0) 
      return State.RUNNING; 
     else 
      return State.STANDING; 
    } 
    public void defineCollector() 
    { 
     BodyDef bdef=new BodyDef(); 
     bdef.position.set(72/Fruits.PPM,32/Fruits.PPM); 
     bdef.type=BodyDef.BodyType.DynamicBody; 
     b2body=world.createBody(bdef); 
     FixtureDef fdef=new FixtureDef(); 
     //PolygonShape shape=new PolygonShape(); 
     CircleShape shape=new CircleShape(); 
     shape.setRadius(20/Fruits.PPM); 
     fdef.shape=shape; 
     b2body.createFixture(fdef); 
    } 
} 
+0

정말 한 번만 넘겨 씁니까? 텍스처 영역은 해당 영역을 사용하고있는 모든 오브젝트에서 잃어버린 텍스처의 영역입니다. – Madmenyo

답변

0

TextureRegion.flip()를 사용 뒤집기하는 이미지의 일정 반전을위한 좋은 방법되지 않습니다 :이 코드입니다. 이 작업을 수행해야하는 유일한 경우는 이미지를로드 할 때이며 이미지 데이터를 실제로 뒤집어 쓰지 않고 뒤집기 위해 실제로 수정하기 때문에 계산 비용이 많이 들기 때문에 한 번만 수행됩니다.

batch.draw()을 호출 할 때 대신 이미지를 뒤집어서 보내야합니다. 다음은 매개 변수가 더 많은 일괄 호출을 사용하는 방법에 대한 가이드입니다. libgdx: Rotate a texture when drawing it with spritebatch 저는 실제로 질문 게시자입니다. P