libgdx [Texture, TextureRegion, Sprite]

图片显示

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class MyGdxGame extends ApplicationAdapter {
    SpriteBatch batch;
    Texture texture;
    TextureRegion textureRegion;
    Sprite sprite;

    int iconWidth = 128;
    int iconHeight = 256;
    int padding = 100;

    @Override
    public void create () {
        batch = new SpriteBatch();

        texture = new Texture(Gdx.files.internal("data/animation.png"));

        textureRegion = new TextureRegion(texture, 0, 0, iconWidth, iconHeight);
        //textureRegion = new TextureRegion(texture, iconWidth, iconHeight, 0-iconWidth, -iconHeight);

        sprite = new Sprite(textureRegion);
        sprite.setSize(iconWidth * 3, iconHeight * 3);
        sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
        //sprite.setOrigin(0, 0);
        //sprite.setRotation(-30);
        sprite.setPosition(padding + iconWidth + iconWidth*2, padding);
        //sprite.setColor(1, 0, 1, 1);
    }
    @Override
    public void dispose () {
        batch.dispose();
        texture.dispose();
    }
    @Override
    public void render () {
        Gdx.gl.glClearColor(1, 1, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(texture, padding, padding, iconWidth, iconHeight);
        batch.draw(textureRegion, padding+iconWidth, padding, iconWidth*2, iconHeight*2);
        sprite.draw(batch);
        batch.end();
    }
}

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值