【发布时间】:2014-09-14 21:32:12
【问题描述】:
您好,我正在使用 Libgdx 框架为 android 创建游戏。我试图在靠近屏幕顶部的 X 轴中间放置一个精灵。我可以做到这一点,但由于精灵需要旋转 90 度(以节省精灵表上的空间),它会导致某种偏移,我不明白为什么。我相信这是因为原点旋转,但我尝试将原点设置为精灵的中心,但它仍然无法按计划工作。请您帮我理解为什么旋转会导致偏移以及如何修复它,谢谢。
regions [1] = new TextureRegion(menu, 395, 0, 115, 320);
logo=new Sprite(regions[1]);// the sprite
logo.setPosition(W/2-logo.getWidth()/2,H*0.95f); //draw right in the middle of X and 95% up Y
logo.rotate(90); //rotate the sprite 90 degrees
logo.setOrigin(logo.getWidth()/2,logo.getHeight()/2); //rotate around the centre of the sprite
logo.draw(spriteBatch); //in render method draw the sprite
【问题讨论】:
-
如果我改变 logo.setPosition(W/2-logo.getWidth()/2,H*0.95f); to logo.setPosition(W/2-logo.getWidth()/2,0);由于某种原因,它将精灵定位在 y 轴的几乎一半而不是底部。