2013-09-07 1 views
0

내 이미지가 있습니다 (설명을 위해 Image.png이라고 말하면 됨). 그리고 내가 그린 몸에 맞게 잘 확대하려고합니다. 시체와 모든 디버그와 함께 작동하지만 그것의 팬이 아니에요 ... SpriteBatch 화면에 배경 이미지를 그릴 것입니다 (너무 규모가 좋을 것입니다). Image.png을 렌더링 된 동적 몸체와 동일한 크기/위치로 스케일하는 방법은 무엇입니까?LibGDX SpriteBatches로 이미지 크기 조절

편집 : 이미지를 그리는 동안, 나는

이 몸 만들기 .. 그들이 시체를 렌더링 디버그와 일치하는 위선적 인 말투 :

   BodyDef bodydef2 = new BodyDef(); 
       bodydef2.type = BodyType.DynamicBody; 
       bodydef2.position.set(camera.viewportWidth + 30.0f, (int)(Math.random()*camera.viewportHeight)%(LastPlatformY+5)+20); 
       //System.out.println(bodydef2.position.y + " " + LastPlatformY); 
       Body block = world.createBody(bodydef2); 
       PolygonShape Shape2 = new PolygonShape(); 
       Shape2.setAsBox(750*WORLD_TO_BOX, 200*WORLD_TO_BOX); 
       FixtureDef fixtureDef2 = new FixtureDef(); 
       fixtureDef2.shape = Shape2; 
       fixtureDef2.density = 1000.0f; 
       fixtureDef2.friction = 0.0f; 
       fixtureDef2.restitution = 0; 
       block.setLinearVelocity(new Vector2((float) (Platform_Velocity*-1), 0)); 
       block.createFixture(fixtureDef2); 
       //Lock 'block' to X-Axis, Relative to floor. 
       PrismaticJointDef jointDef = new PrismaticJointDef(); 
       jointDef.collideConnected = true; 
       jointDef.initialize(block, groundBody, block.getWorldCenter(), new Vector2(1, 0)); 
       world.createJoint(jointDef); 
       Platforms.add(block); 
       Platforms_Created++; 
       LastPlatformY = (int)bodydef2.position.y; 

그리기 이미지 :

sp.draw(platforms, (float)(Platforms.get(i).getPosition().x), (float)(Platforms.get(i).getPosition().y), 75,20); 

수정 # 2 : 카메라가 화면 크기보다 작 으면 위치 변동에 대한 보상을해야합니다. 문제가 해결되었습니다.

답변

1

몸을 만드는 동안 몸의 크기를 두 변수로 저장 한 다음 appropriate 그리기 방법을 호출하십시오. 개체 호출의 위치를 ​​가져 오려면 body.getPosition()을 호출하십시오.

예를

Texture t = assetManager.get("your texture", Texture.class); 

BodyDef bodyDef = new BodyDef(); 
body.type = BodyType.DynamicBody 

float width = 64 * WORLD_TO_BOX; 
float height = 64 * WORLD_TO_BOX; 

Shape shape = new PolygonShape(); 
float[] points = new float[]{0,0,width,0,width,height,0, height}; 
shape.set(points); 
FixtureDef def = new FixtureDef(); 
def.shape = shape; 
... 
body.createFixture(def); 
shape.dispose(); 

를 들어

그리고 나중에

public void render(Spritebatch batch) { 
    batch.draw(t, body.getPosition().x * BOX_TO_WORLD, body.getPosition().y * BOX_TO_WORLD, width * BOX_TO_WORLD, height * BOX_TO_WORLD); 
} 
+0

가'BOX_TO_WORLD' 무엇을 그릴 할 때? – Chris

+0

는 BOX_TO_WORLD을 알아 냈지만 이미지가 보이는 몸으로 이미지를 정렬하기 위해 수학이 꺼졌습니다. – Chris