Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何以规定的速度连续旋转精灵?以及关于游戏编程的一般问题_Java_Android_Libgdx - Fatal编程技术网

Java 如何以规定的速度连续旋转精灵?以及关于游戏编程的一般问题

Java 如何以规定的速度连续旋转精灵?以及关于游戏编程的一般问题,java,android,libgdx,Java,Android,Libgdx,我有一个图像被渲染: public void render(float delta) { batch.begin(); batch.draw(new Sprite(new Texture("img1.png"), 64, 64), x, y); batch.end() 使用X和Y根据屏幕的分辨率将精灵定位在屏幕中央。 我知道我可以用它来旋转,但我如何连续旋转呢?我想我需要以某种方式使用增量时间,例如,x+=50*Gdx.graphics.getDeltaTime()但这

我有一个图像被渲染:

public void render(float delta) {
    batch.begin();
    batch.draw(new Sprite(new Texture("img1.png"), 64, 64), x, y);
    batch.end()

使用X和Y根据屏幕的分辨率将精灵定位在屏幕中央。

  • 我知道我可以用它来旋转,但我如何连续旋转呢?我想我需要以某种方式使用增量时间,例如,
    x+=50*Gdx.graphics.getDeltaTime()但这不会连续旋转它。图像显示一帧,然后跳转到其他位置显示一帧(看起来像是逐帧平移)

  • 如果我希望(一个)精灵具有多个碰撞检测(例如,每个彩色弧的反应不同,那么在顶部覆盖一个不可见的圆,该圆随弧移动,并在该圆上使用数学方法可以解决此问题吗?而不是为每个彩色弧分别设置一个精灵。有更简单的方法吗

  • 对于游戏来说,不使用layouts/XML来设计关卡(即硬编码)可以吗?这会使应用程序更难兼容多个屏幕分辨率吗


  • 我是新手,所以我希望这些问题有意义。

    用这种方式永远旋转你的精灵

    public class TestGame extends Game {
    
        SpriteBatch spriteBatch;
        Sprite ball;
        Texture ballTex;
        private int spriteRotationSpeed=1;
    
        @Override
        public void create() {
    
            spriteBatch=new SpriteBatch();
            ballTex=new Texture("image/bone.png");
            ball=new Sprite(ballTex);
            ball.setSize(50,50);
            ball.setOrigin(25,25);
            ball.setPosition(0,0);
    
    
        }
    
        @Override
        public void render() {
            super.render();
    
            Gdx.gl.glClearColor(1,1,1,1);
            gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    
            spriteBatch.begin();
            ball.draw(spriteBatch);
            spriteBatch.end();
            rotateSprite();
        }
    
        private void rotateSprite(){
    
            float rotation=ball.getRotation();
            rotation+=spriteRotationSpeed;
            if(rotation>360)
                rotation-=360;
            ball.setRotation(rotation);
        }
    
        @Override
        public void resize(int width, int height) {
            super.resize(width, height);
        }
    
        @Override
        public void dispose() {
            super.dispose();
            ballTex.dispose();
            spriteBatch.dispose();
        }
    }
    

    没有任何批处理的方法。绘制(精灵,x,y);其中精灵是精灵类的对象。你的精灵是纹理对象还是纹理区域?它是纹理对象。我编辑了这篇文章,现在应该更清楚了。