粒子对制作画面特效很有用,可以使用Particle Editor进行自行编辑粒子效果,跟图片一起生成.p粒子文件,然后导入到程序中使用。

本文所用的粒子效果是基于其自带的demo的。

实例:

 package com.fxb.newtest;

 import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEmitter;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Array; public class Lib008_Particle extends ApplicationAdapter{ ParticleEffect effect;
InputProcessor processor; float positionX;
float positionY; SpriteBatch batch; Array<ParticleEmitter> sEmitter;
int index = ;
int maxSize; @Override
public void create() {
// TODO Auto-generated method stub
batch = new SpriteBatch();
effect = new ParticleEffect();
effect.load( Gdx.files.internal("particle/test.p"), Gdx.files.internal("particle/") );
maxSize = effect.getEmitters().size; positionX = Gdx.graphics.getWidth()/;
positionY = Gdx.graphics.getHeight()/; //processor = new InputProcessor(){
processor = new InputAdapter(){
@Override
public boolean keyDown(int keycode) {
// TODO Auto-generated method stub
if( keycode == Input.Keys.SPACE ){
index = (++index)%maxSize;
effect.getEmitters().clear();
effect.getEmitters().add( sEmitter.get(index) );
}
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
positionX = screenX;
positionY = Gdx.graphics.getHeight()-screenY;
return false;
}
}; Gdx.input.setInputProcessor( processor ); sEmitter = new Array<ParticleEmitter>();
for( ParticleEmitter emitter : effect.getEmitters() ){
sEmitter.add( emitter );
}
effect.getEmitters().clear();
effect.getEmitters().add( sEmitter.get(index) );
} @Override
public void render() {
// TODO Auto-generated method stub
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT );
effect.setPosition( positionX, positionY ); float delta = Gdx.graphics.getDeltaTime();
batch.begin();
effect.draw( batch, delta );
batch.end(); } @Override
public void dispose() {
// TODO Auto-generated method stub
batch.dispose();
effect.dispose();
} }

运行效果:

这个粒子一共有4层,每按一次空格键就会切换一层,然后显示对应的粒子效果。

libgdx学习记录10——Particle粒子的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. libgdx学习记录12——圆角矩形CircleRect

    libgdx提供了ShapeRenderer这个工具,用它可以画点.画线.画圆.画矩形.画椭圆.画扇形,但是没有提供画圆角矩形的方法. 刚开始自己尝试分成8端,4端画直线,4端画扇形,发现多了半径几部 ...

  7. libgdx学习记录3——动画Animation

    libgdx动画采用Animation实现,即通过帧动画实现. 代码如下: package com.fxb.newtest; import com.badlogic.gdx.ApplicationAd ...

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

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

  9. libgdx学习记录25——Rectangle与Circle是否重叠

    Rect与Circle重叠有三种情况: 1. Rect至少有一个角在Circle里面 2. Circle与Rect的左边或右边相交,或者Circle在Rect内 3. Circle与Rect的顶边或底 ...

随机推荐

  1. 【转】Linux配置NTP时间同步服务器

    分布式程序通常需要运行在一个统一的时间环境里. 转自:http://blog.csdn.net/mengfanzhundsc/article/details/62046562 安装NTP:yum in ...

  2. pytest+allure+jenkins +python2.7

    pip install lxml==3.8.0 pip install pytest-allure-adaptor

  3. innodb 表锁和行锁

    表锁  表锁相关结构: table->locks:数据字典table保存这个表上的所有表锁信息 trx->lock.table_locks:每个事务trx保存该事务所加的所有表锁信息 tr ...

  4. 为 Azure Resource Manager 中的虚拟机设置 WinRM 访问权限

    Azure 服务管理中的 WinRM 与 Azure Resource Manager Note Azure 具有用于创建和处理资源的两个不同的部署模型:Resource Manager 和经典. 本 ...

  5. jquery 比较全面的API中文版地址

    jquery中文API地址 里面有对各个版本的jquery的属性.方法等都有全面的介绍加例子,值得拥有!

  6. python给邮箱发送消息

    首先要用到两个模块  并且大同你的发送邮箱smtp 最开始测试没打通了好久 smtplib是提供邮箱smtp服务, email是提供你发送消息的格式之类服务 import smtplib from e ...

  7. 【转】Ubuntu做日常开发电脑的系统是一种怎样的体验

    [原文]https://www.toutiao.com/i6594291159911105031/ Ubuntu 我现在已经基本不开windows了.学习娱乐开发基本都在Ubuntu 首先你要接受的是 ...

  8. maven的下载与安装

    下载路径:http://maven.apache.org/download.cgi 选择打红线的进行下载,我用的版本是3.3.9, 下载后解压该文件,解压后的文件内容如下: 解压完成后配置maven的 ...

  9. 2017 SDN第一次作业

    (1)我会选择的,因为网络现在越来越重要,各行各业都离不开网络,这个方向可以适合各种岗位,感觉比较容易就业.但选这个课是为了多学一点东西,没想太多,嘎嘎嘎. (2)SDNLAB,是一个SDN的大的中文 ...

  10. Alpha课堂展示(麻瓜制造者)

    目录 成员简介 演示动态图 预期用户量 演示动态图 目标用户视频 分工协作 项目管理 质量控制 团队角色与具体贡献 用户反馈 成员简介 刘双玉 http://www.cnblogs.com/liu42 ...