对人体画精灵 - 摄像头查看端口和调整
问题描述:
我画精灵uppon机构,用此方法(我的身体里面的包装):对人体画精灵 - 摄像头查看端口和调整
private void drawBaseSprite(Batch batch){
Sprite baseSprite = this.getBaseSprite();
Vector3 bodyPixelPos = camera.project(new Vector3(body.getPosition().x, body.getPosition().y, 0));
// TODO: 17/11/16 Review this
float w = scale * (baseSprite.getTexture().getWidth())/camera.zoom;
float h = scale * (baseSprite.getTexture().getHeight())/camera.zoom ;
baseSprite.setSize(w,h);
baseSprite.setOrigin(w/2, h/2);
baseSprite.setPosition(bodyPixelPos.x -w/2, bodyPixelPos.y - h/2);
baseSprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);
baseSprite.draw(batch);
}
一切都很好,直到我尝试调整Windows。嗯,我跟随此调整大小逻辑(实施屏幕):
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
stage.camera.setToOrtho(false, Constants.VIEWPORT_HEIGHT *width/(float)height, Constants.VIEWPORT_HEIGHT);
}
我觉得这是荒谬的,因为这样的:
float w = scale * (baseSprite.getTexture().getWidth())/camera.zoom;
float h = scale * (baseSprite.getTexture().getHeight())/camera.zoom ;
不会改变,而图像是x-scaled。
答
我正确理解你的问题是图像不能停留在身体上方吗?
如果是这样,它没有的原因是您设置的图像相对于相机的大小,而不是它应该覆盖的身体。当相机的变焦被改变时,您调整图像的大小,但不调整主体,并且它们不同步。
我会建议改变你的逻辑,使得图像的高度/宽度完全由身体决定,而你的身体根据相机缩放进行缩放。
答
嗯,这解决了我的问题,但我仍然不知道为什么。
private void drawBaseSprite(Batch batch){
Sprite baseSprite = this.getBaseSprite();
batch.setProjectionMatrix(camera.combined);
float someScale = 0.1f;
float w = scale * (baseSprite.getTexture().getWidth())/camera.zoom *someScale;
float h = scale * (baseSprite.getTexture().getHeight())/camera.zoom *someScale;
Vector3 bodyPixelPos = camera.project(new Vector3(body.getPosition().x, body.getPosition().y, 0))
.scl(someScale*camera.viewportHeight/(Gdx.graphics.getHeight()/20f)).sub(w/2, h/2, 0);
baseSprite.setSize(w,h);
baseSprite.setOrigin(w/2, h/2);
baseSprite.setPosition(bodyPixelPos.x, bodyPixelPos.y);
baseSprite.setRotation(body.getAngle() * MathUtils.radiansToDegrees);
baseSprite.draw(batch);
}
谢谢回答,但我跟踪的子画面尺寸: Gdx.app.log(this.getClass()getSimpleName(), “W: ”+ W +“ H”。+ H); 并且即使在调整大小之后它们也不会改变,因为相机的缩放也不会改变(仅查看端口改变)。 – neogineer