簡體   English   中英

Sprite的旋轉,libgdx android

[英]Rotation of sprite, libgdx android

我想讓我的籃球精靈旋轉。 如何使我的Sprite根據增量時間逆時針旋轉? 你有計算嗎?

每當您想旋轉球時,請調用rotationSprite()方法。

看一下我的測試代碼。

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();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM