2016-06-05 7 views
0

텍스처의 원래 크기 (256,056)로 스프라이트를 (0,0)에 그릴 때 잘 동작하지만 위치 나 크기를 변경하면 스프라이트가 엉망입니다. 여기 코드입니다 :LibGdx 스케일링 대신 텍스처 자르기

private SpriteBatch batch; 
private Sprite sprite; 
private OrthographicCamera camera; 

@Override 
public void create() { 
    camera=new OrthographicCamera(600,600); 
    camera.position.set(0,0,0); 
    camera.update(); 
    batch=new SpriteBatch(); 
    sprite=new Sprite(new Texture("TestBlock_01.png"),0,0,256,256); 
} 

@Override 
public void render() { 
    Gdx.gl.glClearColor(1, 0, 0, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
    batch.begin(); 
    batch.setProjectionMatrix(camera.combined); 
    batch.draw(sprite,sprite.getX(),sprite.getY(),sprite.getWidth(),sprite.getHeight()); 
    batch.end(); 
} 

resault : enter image description here

는 어떻게 해결할 수 : enter image description here

하지만 지금은 위치에 크기 (-100, -100,100,100)를 변경하는 경우 그것?

+0

here을 같이 사용'sprite.draw (배치)'이 아닌'batch.draw (스프라이트, ...); '. Sprite가 TextureRegion을 확장하도록 libgdx의 근본적인 설계 문제라고 부를 수 있습니다. 다음 주요 버전에서 수정 될 것으로 기대됩니다. – Xoppa

답변

0

대답은

sprite=new Sprite(Texture); 
sprite.setPosition(x,y); 
sprite.setSize(width height); 
+0

생성자를 나누는 것은 아무런 영향이 없습니다. –

+0

생성자가 srcX, srcY, srcWidth 및 srcHeight 변수를 변경합니다. 이들은 x, y, width, height와는 다른 변수입니다. –

0

sprite=new Sprite(Texture,x,y,width,height); 

를 대체하는 것입니다 당신이 규모와 위치 changing.As와 함께 완벽하게 작동하는 스프라이트 원점을 설정해야합니다 생각 here

void setOrigin(float originX, float originY) 
Sets the origin in relation to the sprite's position for scaling and rotation. 
설명

또한 매개 변수 origi를 사용하여 render에서 draw 메소드를 호출하십시오. nX, OriginY 완벽하게 회전해야하는 경우.

void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) 

Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.