好吧,我真的很困惑,我以前旋转过精灵,在船穿过海洋时没有旋转问题,但由于某种原因,这次我遇到了一个很大的问题。所以我在资源文件中创建了一个纹理,但不是静态纹理。我使用以下方法加载纹理:
class Assets{
Texture img;
public Assets(){
img = new Texture(Gdx.files.internal("images/PNG.png")
然后我调用来调用主类中的资产
Assets assets = new Assets()
然后我有一个班,就是这个主角的动画师,因为他的动画与其他角色非常不同。
class Animations{
Guy MYGUY;
Texture firstTexture;
ArrayList<Texture> running;
Sprite CurrentSprite;
public Animations(Texture standingStill, Guy myGuy){
MYGUY = myGuy;
firstTexture = standingStill;
running = new ArrayList<Texture>();
running.add(firstTexture);
CurrentSprite = new Sprite(firstTexture);
public void update (int direction, int state){
CurrentSprite.setPosition(MYGUY.X, MYGUY.Y)
// I have a switch here, but it does nothing yet because I haven't added in different actions for the character.
//However I do have a switch for direction, because that is important right now
switch(state){
case Guy.LEFT:
CurrentSprite.set rotation(180);
//yes there are more, but even rotating 180 won't work correctly
}
然后我有一个渲染器类来绘制所有内容,我在一个名为myLand
的世界对象中有对象MyGuy
,我用绘制它
myLand.GUY.animation.CurrentSprite(batch);
所以我的问题出现在旋转上,每当它旋转180度时,它似乎总是围绕坐标(0,0)而不是精灵的中心旋转。所以它通常会在我向右移动五步的地方结束,但如果我试图向左移动,它确实会向后移动两倍的距离,但相机的位置保持不变,这个家伙通常会从屏幕的左侧或右侧消失。
尝试使用rotate(...)
方法而不是setRotation(...).
带setOrigin(widthSprite2, heightSprite2)
该动作会旋转精灵本身。
尝试
sprite.setOriginCenter();
这应该有助于
不用旋转精灵,只需用以下一行翻转即可:
CurrentSprite.flip(true, false);
第一个布尔值是X翻转(向左移动时要设置为true),第二个是Y翻转。