zoukankan      html  css  js  c++  java
  • libgdx学习记录1——图片显示Texture

    libgdx底层采用opengl渲染,对图片进行了优化处理,与android原生态的bitmap不太一样。

    相比而言,效率要高一些,不过只支持png,jpg,bmp三种格式。

    显示中,一般将图片放在assets文件下,表示是Gdx的内部文件。

    gl1.x使用的图片的宽高必须是2的整次幂,而在gl2.0以后的版本则没有此限制。

    使用的版本为libgx 0.9.9。

    代码如下:

    package com.fxb.bird;
    
    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.SpriteBatch;
    import com.badlogic.gdx.graphics.g2d.TextureRegion;
    
    public class FlappyBird extends ApplicationAdapter{
        
        Texture texture;
        SpriteBatch batch;
        
        TextureRegion region1;
        TextureRegion region2;
        
        @Override
        public void create() {
            // TODO Auto-generated method stub
            texture = new Texture( Gdx.files.internal("data/badlogic.jpg") );
            batch = new SpriteBatch();
            
            region1 = new TextureRegion( texture );
            region2 = new TextureRegion( region1, 0, 0, region1.getRegionWidth()/2, region1.getRegionHeight()/2 );
            
        }
        @Override
        public void render() {
            // TODO Auto-generated method stub
            Gdx.gl.glClearColor(1, 1, 1, 1);
            Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
            
            batch.begin();
            batch.draw( texture, 50, 50 );
            batch.draw( region1, 400, 50, region1.getRegionWidth()/2, region1.getRegionHeight()/2 );
            batch.draw( region2, 600, 50 );
            batch.end();
        }
        @Override
        public void dispose() {
            // TODO Auto-generated method stub
            super.dispose();
        }
        
    }

    显示效果如下:

     很基本,很简单,也是入门,呵呵。。。

  • 相关阅读:
    cookie+session,会话时间设定
    input中id和name属性的区别。
    框架和设计模式的区别
    Java数字格式化输出时前面补0
    DDL_数据库模式定义语言
    7.JAVA_SE复习(文件)
    (python)数据结构---集合
    (python)数据结构---字典
    (python)数据结构---字符串
    (python)排序算法
  • 原文地址:https://www.cnblogs.com/MiniHouse/p/3738574.html
Copyright © 2011-2022 走看看