【问题标题】:setCenter in Libgdx not available in nightlies package, and setOrigin not working well?Libgdx 中的 setCenter 在 nightlies 包中不可用,并且 setOrigin 不能正常工作?
【发布时间】:2014-05-07 09:13:20
【问题描述】:

我想更改图像的中心点,位置(在世界中)工作正常,但不是中心点(在精灵中),Sprite API 的链接: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setOriginCenter()

在 Sprite 的方法中只有 setOrigin 可用,并且将其更改为 -100、-100 或 0,0 不会改变任何内容。有人知道为什么吗?

sprite = new Sprite(tex);
sprite.setPosition(pos.x, pos.y);
sprite.setOrigin(-100,-100);//(sprite.getWidth()*0.5f, sprite.getHeight()*0.5f);//(0,0);
sprite.setSize(0.5f, 0.5f);

【问题讨论】:

    标签: java position libgdx sprite


    【解决方案1】:

    使用setOrigin,您可以设置Spriteorigin,它负责rotationscaling。但不影响position
    这意味着,如果您将origin 设置为P(width/2,height/2) 并旋转您的Sprite,它将围绕他的中心旋转。如果您将origin 设置为左​​下角P(0,0),它将围绕该角旋转。
    position 始终位于左下角,不受origin 的影响。
    如果你想保持position 作为中心点,你需要重新计算左下角:

    sprite.setPosition(posVector.x-sprite.getWidth()/2, posVector.y-sprite.getHeight()/2);
    

    请注意,originSprites position 相关。所以P(0,0)是左下角,P(width,height)是右上角。

    【讨论】:

    • 很高兴能帮上忙
    猜你喜欢
    • 1970-01-01
    • 2012-03-01
    • 2020-06-07
    • 1970-01-01
    • 2021-11-23
    • 2015-02-28
    • 2012-07-04
    • 1970-01-01
    • 2015-07-29
    相关资源
    最近更新 更多