您好我正在使用Libgdx框架为Android创建游戏。我试图在靠近屏幕顶部的X轴中间放置一个精灵。我可以做到这一点很好,但由于精灵需要旋转90度(以节省spritesheet上的空间)它会导致某种偏移,我不明白为什么。我相信这是因为原点旋转,但我尝试将原点设置为精灵的中心,但它仍然无法按计划工作。请问你能帮助我理解旋转引起偏移的原因以及如何修复它。谢谢。
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
答案 0 :(得分:1)
旋转后,您可以设置精灵的原点:
logo.rotate(90); //rotate the sprite 90 degrees
logo.setOrigin(logo.getWidth()/2,logo.getHeight()/2); //rotate around the centre of the sprite
你应该反过来做。首先设置原点,然后旋转:
logo.setOrigin(logo.getWidth()/2,logo.getHeight()/2);
logo.rotate(90);