Flare3D游戏特效教程:火拳阿宝

截图预览:

网页预览:http://eko.kooteam.com/flare3d/abao/

 

一 思路

我们在玩游戏的时候,经常能看到一些粒子特效被绑定在武器上,装备上。其实就是将粒子定位在某个对象上。在这篇教程中,我们把火焰粒子绑定在阿宝的两个手掌的骨骼上。

二 准备

现在我们需要一个火焰粒子特效和一个阿宝的模型。

粒子特效我直接拿了yblunan的东西,地址如下:火焰粒子

阿宝的模型在最后附件中提供,值得注意的是,模型中我将左右手掌需要绑定的骨骼命名为fire,fire2。

接下来先看看完整代码,然后逐步讲解。

三 完整代码

 1 package
 2 {
 3     import base.Base;
 4 
 5     import components.BoneController;
 6 
 7     import flare.basic.Scene3D;
 8     import flare.basic.Viewer3D;
 9     import flare.core.Camera3D;
10     import flare.core.Mesh3D;
11     import flare.core.ParticleEmiter3D;
12     import flare.core.Pivot3D;
13     import flare.core.Texture3D;
14     import flare.materials.ParticleMaterial3D;
15     import flare.materials.filters.ColorParticleFilter;
16     import flare.materials.filters.TextureFilter;
17 
18     import flash.display.Bitmap;
19     import flash.events.Event;
20 
21     [SWF(width=800,height=600)]
22     public class TheBao extends Base
23     {
24         [Embed(source="fire.png")]
25         private var Fire:Class;
26 
27         [Embed(source="abao.f3d",mimeType="application/octet-stream")]
28         private var ABao:Class;
29         private var scene:Scene3D;
30         private var bao:Pivot3D;
31         public function TheBao(info:String="粒子绑定骨骼")
32         {
33             super(info);
34             scene=new Viewer3D(this);
35             scene.camera=new Camera3D();
36             scene.camera.z=-250;
37             scene.camera.y=100;
38             //scene.frameRate=10;
39             scene.addEventListener(Scene3D.COMPLETE_EVENT,onCom);
40 
41             bao=scene.addChildFromFile(new ABao);
42 
43         }
44         private function onCom(e:Event):void
45         {
46 
47             var fire:Bitmap=new Fire();
48             var pm:ParticleMaterial3D=new ParticleMaterial3D();
49             pm.filters.push(new TextureFilter(new Texture3D(fire.bitmapData)));
50             pm.filters.push(new ColorParticleFilter([0xffffff,0xffff00,0xff0000,0x000000],[1,.5,.2,0]));
51             pm.build();
52 
53             var fireEmiter:ParticleEmiter3D=new ParticleEmiter3D("",pm,new FireParticle());
54             fireEmiter.particlesLife=20;
55             fireEmiter.emitParticlesPerFrame=50;
56             fireEmiter.rotateX(90);
57             fireEmiter.layer=10;
58 
59             var fireEmiter2:ParticleEmiter3D=new ParticleEmiter3D("",pm,new FireParticle());
60             fireEmiter2.particlesLife=20;
61             fireEmiter2.emitParticlesPerFrame=50;
62             fireEmiter2.rotateX(90);
63             fireEmiter2.layer=11;
64 
65             var baoMesh:Mesh3D=bao.getChildByName("bao") as Mesh3D;
66             fireEmiter.addComponent(new BoneController(baoMesh,"fire"));
67             fireEmiter2.addComponent(new BoneController(baoMesh,"fire2"));
68             scene.addChild(fireEmiter);
69             scene.addChild(fireEmiter2);
70         }
71     }
72 }

 

四 代码分析

首先,创建场景,设定摄像机位置,并加载阿宝的模型

super(info);
scene=new Viewer3D(this);
scene.camera=new Camera3D();
scene.camera.z=-250;
scene.camera.y=100;
scene.addEventListener(Scene3D.COMPLETE_EVENT,onCom);
bao=scene.addChildFromFile(new ABao);

其次,我们来创建火焰粒子

//创建火焰粒子的材质
var fire:Bitmap=new Fire();
var pm:ParticleMaterial3D=new ParticleMaterial3D();
pm.filters.push(new TextureFilter(new Texture3D(fire.bitmapData)));
pm.filters.push(new ColorParticleFilter([0xffffff,0xffff00,0xff0000,0x000000],[1,.5,.2,0]));
pm.build();

//实例化两个火焰粒子
var fireEmiter:ParticleEmiter3D=new ParticleEmiter3D("",pm,new FireParticle());
//粒子的生命,也就是过多久会消失
fireEmiter.particlesLife=20;
//每帧生成多少个粒子
fireEmiter.emitParticlesPerFrame=50;
//将粒子绕x轴旋转了90度,确保发射方向从掌心射出
fireEmiter.rotateX(90);
fireEmiter.layer=10;

var fireEmiter2:ParticleEmiter3D=new ParticleEmiter3D("",pm,new FireParticle());
fireEmiter2.particlesLife=20;
fireEmiter2.emitParticlesPerFrame=50;
fireEmiter2.rotateX(90);
fireEmiter2.layer=11;

再次 我们将火焰粒子绑定到骨骼上,这里用到官方提供的自定义骨骼控制类BoneController

var baoMesh:Mesh3D=bao.getChildByName("bao") as Mesh3D;
fireEmiter.addComponent(new BoneController(baoMesh,"fire"));
fireEmiter2.addComponent(new BoneController(baoMesh,"fire2"));
scene.addChild(fireEmiter);
scene.addChild(fireEmiter2);

五 所有资源打包放出

点击下载 abao

posted @ 2013-01-31 13:43  leo_as南京  阅读(527)  评论(0编辑  收藏  举报