[转帖]Android游戏开发----LibGdx游戏引擎制作微信火焰效果(附源码)_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3838 | 回复: 0   主题: [转帖]Android游戏开发----LibGdx游戏引擎制作微信火焰效果(附源码)        下一篇 
huizai
注册用户
等级:少校
经验:933
发帖:83
精华:0
注册:2013-6-18
状态:离线
发送短消息息给huizai 加好友    发送短消息息给huizai 发消息
发表于: IP:您无权察看 2013-6-26 11:02:38 | [全部帖] [楼主帖] 楼主

转自:http://blog.csdn.net/xn4545945/article/details/9164867#comments

留心的朋友会发现,安装完微信4.5后,会有一个跳动的火焰、并播放《一无所有》的欢迎页。本篇文章模拟的是火焰跳动的效果。

一、LibGdx游戏引擎介绍

LibGdx是一款基于OpenGL ES技术开发的Android游戏引擎,支持Android平台下的2D游戏开发,物理引擎采用Box2D实现

LibGdx是一个跨平台的2D/3D的游戏开发框架,它由Java/C/C++语言编写而成。它基于Apache License, Version 2.0协议,对商业使用和非商业使用均免费。代码托管于Github中。最新版本为0.9.8。

官方网站:http://code.google.com/p/libgdx/

LibGdx单就性能角度来说,堪称是一款非常强大的 Android游戏引擎。

二、粒子特效

为模拟现实中的水、火、雾、气等效果由各种三维软件开发的制作模块,原理是将无数的单个粒子组合使其呈现出固定形态,借由控制器,脚本来控制其整体或单个的运动,模拟出现真实的效果。

三、LibGdx粒子特效编辑器

下载地址:http://code.google.com/p/libgdx/wiki/ParticleEditor

用来编辑粒子效果的编辑器。(参数可以任意尝试设置)

打开后界面如下, 可直接保存效果为my.p,为后续使用。

北京联动北方科技有限公司

四、具体实现

功能:实现一个画面,当手触摸时,火焰随之移动。

核心代码:(my.p放在asset/data目录下,并在该目录下放一张particle.png(为单个粒子的图片文件,文件名唯一))

[java]view plaincopyprint?

  1. package com.example.libgdx_02_Particle; 
  2. import com.badlogic.gdx.ApplicationListener; 
  3. import com.badlogic.gdx.Gdx; 
  4. import com.badlogic.gdx.InputProcessor; 
  5. import com.badlogic.gdx.graphics.GL10; 
  6. import com.badlogic.gdx.graphics.g2d.ParticleEffect; 
  7. import com.badlogic.gdx.graphics.g2d.ParticleEmitter; 
  8. import com.badlogic.gdx.graphics.g2d.SpriteBatch; 
  9. import com.badlogic.gdx.utils.Array; 
  10. public class Game implements ApplicationListener 
  11.       
  12.        SpriteBatch batch; 
  13.        ParticleEffect effect; 
  14.        int index; 
  15.        Array<ParticleEmitter> emitters; 
  16.        int count; 
  17.       
  18.        //一旦ApplicationListener开始运行,render函数就会不停执行 
  19.        @Override 
  20.        public void render()//着色, 渲染. 
  21.        { 
  22.              // TODO Auto-generated method stub 
  23.              Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);//清屏 
  24.              Gdx.gl.glClearColor(0f, 0f, 0f, 0f); 
  25.             
  26.              batch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), 
  27.              Gdx.graphics.getHeight()); 
  28.              Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
  29.              batch.begin(); 
  30.              effect.draw(batch, Gdx.graphics.getDeltaTime()); 
  31.              batch.end(); 
  32.             
  33.        } 
  34.       
  35.        @Override 
  36.        public void create() 
  37.        { 
  38.              //初始化 
  39.              batch = new SpriteBatch(); 
  40.              effect = new ParticleEffect(); 
  41.              //加载文件 
  42.              effect.load(Gdx.files.internal("data/my.p"), 
  43.              Gdx.files.internal("data/")); 
  44.              //设置特效位置 
  45.              effect.setPosition(Gdx.graphics.getWidth() / 2, 
  46.              Gdx.graphics.getHeight() / 2); 
  47.             
  48.              emitters = new Array<ParticleEmitter>(effect.getEmitters()); 
  49.              effect.getEmitters().clear(); 
  50.              effect.getEmitters().add(emitters.get(index)); 
  51.             
  52.              //点击屏幕移动, 设置输入 
  53.              InputProcessor inputProcessor = new InputProcessor() 
  54.              { 
  55.                   
  56.                    @Override 
  57.                    public boolean touchUp(int arg0, int arg1, int arg2, int arg3) 
  58.                    { 
  59.                          return false; 
  60.                    } 
  61.                   
  62.                    @Override 
  63.                    public boolean touchDragged(int arg0, int arg1, int arg2) 
  64.                    { 
  65.                          effect.setPosition(arg0, Gdx.graphics.getHeight() - arg1); 
  66.                          return false; 
  67.                    } 
  68.                   
  69.                    @Override 
  70.                    public boolean touchDown(int arg0, int arg1, int arg2, int arg3) 
  71.                    { 
  72.                          ParticleEmitter emitter = emitters.get(index); 
  73.                          count += 100; 
  74.                          if (count > emitter.getMaxParticleCount()) 
  75.                          emitter.setMaxParticleCount(count * 2); 
  76.                          count = Math.max(0, count); 
  77.                          emitter.getEmission().setHigh( 
  78.                          count / emitter.getLife().getHighMax() * 1000); 
  79.                          effect.getEmitters().clear(); 
  80.                          effect.getEmitters().add(emitter); 
  81.                          return false; 
  82.                    } 
  83.                   
  84.                    @Override 
  85.                    public boolean scrolled(int arg0) 
  86.                    { 
  87.                          // TODO Auto-generated method stub 
  88.                          return false; 
  89.                    } 
  90.                   
  91.                    @Override 
  92.                    public boolean keyUp(int arg0) 
  93.                    { 
  94.                          // TODO Auto-generated method stub 
  95.                          return false; 
  96.                    } 
  97.                   
  98.                    @Override 
  99.                    public boolean keyTyped(char arg0) 
  100.                    { 
  101.                          // TODO Auto-generated method stub 
  102.                          return false; 
  103.                    } 
  104.                   
  105.                    @Override 
  106.                    public boolean keyDown(int arg0) 
  107.                    { 
  108.                          // TODO Auto-generated method stub 
  109.                          return false; 
  110.                    } 
  111.                   
  112.                    @Override 
  113.                    public boolean mouseMoved(int arg0, int arg1) 
  114.                    { 
  115.                          // TODO Auto-generated method stub 
  116.                          return false; 
  117.                    } 
  118.              }; 
  119.              Gdx.input.setInputProcessor(inputProcessor); 
  120.        } 
  121.       
  122.        @Override 
  123.        public void dispose() 
  124.        { 
  125.              // 释放资源 
  126.              batch.dispose(); 
  127.             
  128.        } 
  129.       
  130.        @Override 
  131.        public void pause() 
  132.        { 
  133.              // TODO Auto-generated method stub 
  134.             
  135.        } 
  136.       
  137.        @Override 
  138.        public void resize(int arg0, int arg1) 
  139.        { 
  140.              // TODO Auto-generated method stub 
  141.             
  142.        } 
  143.       
  144.        @Override 
  145.        public void resume() 
  146.        { 
  147.              // TODO Auto-generated method stub 
  148.             
  149.        } 
  150.       


package com.example.libgdx_02_Particle;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
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 Game implements ApplicationListener
{

       SpriteBatch batch;
       ParticleEffect effect;
       int index;
       Array<ParticleEmitter> emitters;
       int count;

       //一旦ApplicationListener开始运行,render函数就会不停执行
       @Override
       public void render()//着色, 渲染.
       {
             // TODO Auto-generated method stub
             Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);//清屏
             Gdx.gl.glClearColor(0f, 0f, 0f, 0f);

             batch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(),
             Gdx.graphics.getHeight());
             Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
             batch.begin();
             effect.draw(batch, Gdx.graphics.getDeltaTime());
             batch.end();

       }

       @Override
       public void create()
       {
             //初始化
             batch = new SpriteBatch();
             effect = new ParticleEffect();
             //加载文件
             effect.load(Gdx.files.internal("data/my.p"),
             Gdx.files.internal("data/"));
             //设置特效位置
             effect.setPosition(Gdx.graphics.getWidth() / 2,
             Gdx.graphics.getHeight() / 2);

             emitters = new Array<ParticleEmitter>(effect.getEmitters());
             effect.getEmitters().clear();
             effect.getEmitters().add(emitters.get(index));

             //点击屏幕移动, 设置输入
             InputProcessor inputProcessor = new InputProcessor()
             {

                   @Override
                   public boolean touchUp(int arg0, int arg1, int arg2, int arg3)
                   {
                         return false;
                   }

                   @Override
                   public boolean touchDragged(int arg0, int arg1, int arg2)
                   {
                         effect.setPosition(arg0, Gdx.graphics.getHeight() - arg1);
                         return false;
                   }

                   @Override
                   public boolean touchDown(int arg0, int arg1, int arg2, int arg3)
                   {
                         ParticleEmitter emitter = emitters.get(index);
                         count += 100;
                         if (count > emitter.getMaxParticleCount())
                         emitter.setMaxParticleCount(count * 2);
                         count = Math.max(0, count);
                         emitter.getEmission().setHigh(
                         count / emitter.getLife().getHighMax() * 1000);
                         effect.getEmitters().clear();
                         effect.getEmitters().add(emitter);
                         return false;
                   }

                   @Override
                   public boolean scrolled(int arg0)
                   {
                         // TODO Auto-generated method stub
                         return false;
                   }

                   @Override
                   public boolean keyUp(int arg0)
                   {
                         // TODO Auto-generated method stub
                         return false;
                   }

                   @Override
                   public boolean keyTyped(char arg0)
                   {
                         // TODO Auto-generated method stub
                         return false;
                   }

                   @Override
                   public boolean keyDown(int arg0)
                   {
                         // TODO Auto-generated method stub
                         return false;
                   }

                   @Override
                   public boolean mouseMoved(int arg0, int arg1)
                   {
                         // TODO Auto-generated method stub
                         return false;
                   }
             };
             Gdx.input.setInputProcessor(inputProcessor);
       }

       @Override
       public void dispose()
       {
             // 释放资源
             batch.dispose();

       }

       @Override
       public void pause()
       {
             // TODO Auto-generated method stub

       }

       @Override
       public void resize(int arg0, int arg1)
       {
             // TODO Auto-generated method stub

       }

       @Override
       public void resume()
       {
             // TODO Auto-generated method stub

       }

}

;

运行效果

北京联动北方科技有限公司

有没有比微信还炫呢??

更多资料: http://www.apkbus.com/android-57456-1-1.html

源码下载http://download.csdn.net/detail/xn4545945/5643035

原创文章,转载请注明出处http://blog.csdn.net/xn4545945




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论