libgdx动画采用Animation实现,即通过帧动画实现。

代码如下:

 package com.fxb.newtest;

 import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; public class Lib002_Animation extends ApplicationAdapter{ Texture texture;
Animation animation;
SpriteBatch batch;
float currentTime = 0; @Override
public void create() {
// TODO Auto-generated method stub
batch = new SpriteBatch();
texture = new Texture( Gdx.files.internal( "data/koalio.png" ) );
TextureRegion region = new TextureRegion( texture );
TextureRegion[] regions = region.split( 18, 26 )[0]; animation = new Animation( 0.1f, regions[1], regions[2], regions[3], regions[4] );
} @Override
public void render() {
// TODO Auto-generated method stub
Gdx.gl.glClearColor( 1, 1, 1, 1 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT ); currentTime += Gdx.graphics.getDeltaTime();
TextureRegion region = animation.getKeyFrame( currentTime, true ); batch.begin();
batch.draw( region, 100, 100, region.getRegionWidth(), region.getRegionHeight() );
batch.end();
} @Override
public void dispose() {
// TODO Auto-generated method stub
super.dispose();
} }

运行效果:

libgdx学习记录3——动画Animation的更多相关文章

  1. libgdx学习记录5——演员Actor

    Actor也是libgdx中非常重要的一个元素,一般与stage配合一起使用.Actor能够设置大小,位置,旋转和动画等. 我们自定义的Actor一般需要继承于Actor,并且重写其中的act和dra ...

  2. libgdx学习记录2——文字显示BitmapFont

    libgdx对中文支持不是太好,主要通过Hireo和ttf字库两种方式实现.本文简单介绍最基本的bitmapfont的用法. 代码如下: package com.fxb.newtest; import ...

  3. libgdx学习记录26——Polygon多边形碰撞检测

    libgdx中Math封装了Polygon这个类,它是由多个定点进行描述实现的,在进行物体间的碰撞时,物体轮廓有时候是不规则的,这时候可以用一个多边形勾勒出其大概的轮廓,对其进行模拟. Polygon ...

  4. libgdx学习记录22——3d物体创建

    libgdx是一个强大的游戏框架,不仅支持2d部分,同时还支持3d部分. libgdx的3d部分投影主要通过PerspectiveCamera实现. 物体的显示过程: 1. 创建远景相机,角度一般设为 ...

  5. libgdx学习记录20——多线程MultiThread资源处理

    在libgdx中,一般的逻辑流程都在rende()函数中执行,这个函数是由opengl的渲染线程调用的,一般的图形显示和逻辑处理都在这个线程中. 一般情形下,在这个线程中处理就行了.但是当某些逻辑处理 ...

  6. libgdx学习记录19——图片动态打包PixmapPacker

    libgdx中,opengl 1.x要求图片长宽必须为2的整次幂,一般有如下解决方法 1. 将opengl 1.x改为opengl 2.0.(libgdx 1.0版本后不支持1.x,当然不存在这个问题 ...

  7. libgdx学习记录18——Box2d物理引擎

    libgdx封装了Box2D物理引擎,通过这个引擎能够模拟物理现实,使设计出的游戏更具有真实感. libgdx中,Box2d程序的大概过程: 1. 创建物理世界world,并设置重力加速度. 2. 创 ...

  8. libgdx学习记录17——照相机Camera

    照相机在libgdx中的地位举足轻重,贯穿于整个游戏开发过程的始终.一般我们都通过Stage封装而间接使用Camera,同时我们也可以单独使用Camera以完成背景的移动.元素的放大.旋转等操作. C ...

  9. libgdx学习记录16——资源加载器AssetManager

    AssetManager用于对游戏中的资源进行加载.当游戏中资源(图片.背景音乐等)较大时,加载时会需要较长时间,可能会阻塞渲染线程,使用AssetManager可以解决此类问题. 主要优点: 1. ...

随机推荐

  1. jQuery实现动态分割div

    转自:https://www.cnblogs.com/herd/p/6014848.html 演示地址:http://www.vfkjsd.cn/div/2/div.html

  2. 10.17 elemen.js

    今天终于把element.js的官方文档看完了,主要是基础组件的用法,看的时候有种之前学bootstrap的感觉,似曾相识. 虽然它是基于VUE的,但是展示给我们的代码已经精简到不用会VUE也能看懂了 ...

  3. 批量替换表中某字段的“\t”

    update dbo.Hishop_Products set [Description]=replace(cast([Description] as varchar(8000)),' ',' ')

  4. LeetCode解题录-1~50

    [leetcode]1. Two Sum两数之和 Two Pointers, HashMap Easy [leetcode]2. Add Two Numbers两数相加 Math, LinkedLis ...

  5. swift 自动布局设置 tableview 的 tableHeaderView 的高度

    class headerView: UIView { var whiteView = UIView().then { $.backgroundColor = UIColor.red } overrid ...

  6. Tigase-01 使用spark或spi登录Tigase服务器

    喜欢研究IM技术的同学们,欢迎加入群 310790965 一起来学习,有什么问题可以一起讨论. 本源码是基于tigase v7.1.0来分析的,群里文件中会上传一个完整能跑的源代码压缩包,网上tiga ...

  7. Linux查看机器负载

    负载(load)是linux机器的一个重要指标,直观了反应了机器当前的状态.如果机器负载过高,那么对机器的操作将难以进行. Linux的负载高,主要是由于CPU使用.内存使用.IO消耗三部分构成.任意 ...

  8. yarn查询/cluster/nodes均返回localhost

    背景: 1.已禁用ipv6. 2.所有节点的/etc/hosts正确配置,任务在ResourceManager提交. 3.yarn-site.xml中指定了 yarn.resourcemanager. ...

  9. hashmap源码研究

    概述 在官方文档中是这样描述HashMap的: Hash table based implementation of the Map interface. This implementation pr ...

  10. [Hbase]Hbase章4 Hbase分区爆了

    又搞事了,发生了啥事呢:生产分区数暴了,What? 目前的情况: 前提:单Region Server分区上限设置为1000: 目前A表的数据量半年达到25E,20G一分区,达到了900多个分区,这是要 ...