LibGDX问题旋转精灵 [英] LibGDX problems rotating sprite

查看:156
本文介绍了LibGDX问题旋转精灵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我真的很困惑,我之前已经旋转过精灵,并且没有问题,例如在海洋中旋转船时,但是由于某种原因,这次我遇到了一个很大的问题.因此,我在资产文件中创建了纹理,但没有在静态纹理中创建.我使用以下方法加载纹理:

OK so I'm really confused I've rotated sprites before and had no problem such as rotating a boat as it moves through an ocean, but for some reason I'm having a really big problem this time. So I create a texture in an assets file, but not static textures. I load the texture using the following:

class Assets{
    Texture img;
    public Assets(){
        img = new Texture(Gdx.files.internal("images/PNG.png")

然后我通过调用以下内容来调用主类中的资产:

And then I call the assets in the main class by calling:

Assets assets = new Assets()

然后我有一个专门为这个主要角色设计的动画师,因为他的动画与其他角色截然不同且不同.

And then I have a class that is an animator just for this main character because his animation is so different and varied from other characters.

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,并使用了以下图形进行绘制:

Then I have a renderer class to draw everything, i have the object MyGuy in an object for the world called myLand and I draw it with:

myLand.GUY.animation.CurrentSprite(batch);

所以我的问题出现在旋转上,每旋转180度,它似乎总是围绕坐标(0,0)旋转,而不是精灵的中心旋转.因此它通常会以我向右移动五个的位置结束,但是如果我尝试向左移动,则向后移动的距离会翻倍,但相机位置保持不变,并且该家伙通常会从左侧或右侧消失屏幕.

So my problem arises on the rotation, whenever it rotates 180 degrees it seems to always rotate around the coordinates (0, 0) instead of the center of the sprite. So it usually ends up where I move like five to the right, but then if I try to go left it does double the distance backwards, but the camera position stays the same, and the guy usually disappears off the left or right side of the screen.

推荐答案

尝试使用rotate(...)方法代替setRotation(...).

使用setOrigin(widthSprite\2, heightSprite\2)

该动作会自动旋转精灵.

With setOrigin(widthSprite\2, heightSprite\2)

That action rotate sprite itself.

这篇关于LibGDX问题旋转精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆