粒子对制作画面特效很有用,可以使用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. 用JS实现控制浏览器F12与右键功能

    本文出至:新太潮流网络博客 用JS实现控制浏览器F12与右键功能,防止恶意窃取代码,或其他直接复制进去就好 //禁用右键 document.oncontextmenu = function () { ...

  2. windows安装Anaconda3

    目录 windows安装Anaconda3 环境 安装 windows安装Anaconda3 by 铁乐与猫 环境 windows7 64位 Anaconda3 5.2.0版本 windows64位 ...

  3. Qt在控件未显示时如何获取正确的控件尺寸

    因为打算全屏显示一个对话框,而对话框内有几个QLabel的尺寸要在确定QLabel可用的最大尺寸后,再根据内容调整一次,所以在对话框构造函数内就想确定QLabel的最大尺寸,但因为QWidget::u ...

  4. 8.1Solr API使用(分页,高亮)

    转载请出自出处:http://www.cnblogs.com/hd3013779515/ 一.Solr Deep Paging(深分页) 长期以来,我们一直有一个深分页问题.如果直接跳到很靠后的页数, ...

  5. POJ3801 Crazy Circuits

    嘟嘟嘟 上下界网络流之最小流. 建图不说啦,裸的. 在有附加源\(S\)和附加汇\(T\)的图上跑完后,删除和\(S, T\)相连的边.然后因为可能流多了,所以现在应该退流,于是我们从\(t\)到\( ...

  6. vagrant特性——基于docker开发环境(docker和vagrant的结合)-2-命令

    Docker Commands Docker provider公开了一些额外的vagrant命令,这些命令对于与Docker容器交互非常有用.这有助于你在vagrant之上的工作流程,这样你就可以在底 ...

  7. ORA-27125: unable to create shared memory segment的解决方法(转)

    ORA-27125: unable to create shared memory segment的解决方法(转) # Kernel sysctl configuration file for Red ...

  8. tsconfig.json

    概述 如果一个目录下存在一个tsconfig.json文件,那么它意味着这个目录是TypeScript项目的根目录. tsconfig.json文件中指定了用来编译这个项目的根文件和编译选项. 一个项 ...

  9. shiro实战系列(十四)之配置

    Shiro 被设计成能够在任何环境下工作,从最简单的命令行应用程序到最大的的企业群集应用.由于环境的多样性,使得许多配置机制适用于它的配置. 一. 许多配置选项 Shiro的SecurityManag ...

  10. django表格form无法保存评论排查步骤

    初学django项目,在网上找了个blog教程,还是很不错的,这里感谢一下博主https://www.zmrenwu.com/post/2/ 这个项目适合django初学者,是一个完整的blog项目 ...