`
txf2004
  • 浏览: 7233716 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

FLASH Smoke simulation

阅读更多

【my word】

图形学里面,在标准的3D API下面模拟这些现象已经很成熟了, 以前也看见过用粒子模拟的这些效果(不过没有收录),这次也就权当补上,这些模拟并非数值上的模拟,仅仅是视觉上的模拟,不过在一般的游戏应用中已经足够了。

原文:http://asgamer.com/2009/game-graphic-design-smoke-flash

----------------------------------------------------------------------------------------------------------------------------------------------------

Graphic Design - Making Smoke in Flash

Flash Animated Fire Smoke Alarms Action Flash Games Photoshop Tutorial

What good is smoke? Let’s think for a second. What produces smoke? Failing mechanical equipment, grenades, guns, volcanoes, factories, fires, vehicles, and probably a million other things. So does your Flash game need smoke, well, that’s for your to decide. But the fact of the matter is we can produce some rather convincing smoke with a very simple bit of code and a little Adobe Photoshop. So let’s make some smoke.

Creating Our Smoke Graphic Texture in Photoshop

Open up Photoshop and create a new document 40×40. Now go to your brushes window (F5) and select the brush in the image below.

thepuff-0

and change a few of the settings on this brush as in the image below.

thepuff-01

Now simply go in the middle of your canvas and make a smoke puff. Set the opacity down a little maybe 20% and start drawing. Make a little texture to it.

thepuff-1

It should look a little something like the above. Take your puff and save it as a png. If you don’t like how your puff looks then you can feel free to copy mine above. Just save it, it’s a png and will work well.

Setting Our Smoke Puff up in Flash

Okay. Very simple, Import from the Library your smoke puff. File > Import > Import to Library…

Now just drop the image of your smoke puff dead center in the middle of a new MovieClip, name is SmokePuff. Your stage should look like the image below:

thepuff-2

Okay so one more thing left to do and you are set. Right click your SmokePuff MovieClip from the Library(CTRL+L) and select Linkage… Now just copy what you see below and click okay.

thepuff-3

One last thing… set your document class to Main. Nice. Flash is ready, let’s start writing some code.

Writing the Actionscript to make some Smoke

Okay guys, this has been a super quick tutorial so far. Lots of images and little to say. Let’s get into the code that will say everything we need to make our smoke fly beautifully. Honestly guys this code is so straight forward, let me just post the Smokepuff.as class at once and explain it later. Make sure you save it to com/asgamer/graphics

package com.asgamer.graphics
{ import flash.display.BlendMode;
	import flash.display.MovieClip;
	import flash.events.Event; public class Smokepuff extends MovieClip
	{ public var vx:Number;
		public var vy:Number; public function Smokepuff() : void
		{
			alpha = Math.random();
			vx = Math.random() - Math.random();
			vy = Math.random() * 3 - 5;
			scaleX = scaleY = Math.random();
			addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
		} private function loop(e:Event) : void
		{
			alpha -= 0.01;
			y += vy;
			x += vx;
			scaleX = scaleY += 0.02; if (alpha 

Let’s break it down:

  • We have a vx(velocity x) and vy(velocity y) class variable. Both are numbers and will hold the velocity of our smoke puff.
  • In our constructor we set up some basic information we need to use through our smoke puff.
  • alpha = Math.random(); We need some diversity with our puffs, let’s make them all start at a random alpha.
  • vx = Math.random() - Math.random(); Set the vx to something randomly between -1 and 1
  • vy = Math.random() * 3 - 5; We need a negative vy so our smoke will move upward. This line will give us a number between -5 and -2 and some diversity in the speed of our smoke.
  • scaleX = scaleY = Math.random(); Choose a random value to start our smoke’s size. Once again to add some diversity.
  • addEventListener(Event.ENTER_FRAME, loop, false, 0, true); each time we enter a frame… call loop.
  • alpha -= 0.01; Make the alpha go down with each frame.
  • y += vy; x += vx; Apply our velocity to our smokepuff.
  • scaleX = scaleY += 0.02; Make our smoke spread out as it travels.
  • if (alpha If our smoke is no longer visible… let’s get rid of it.
  • removeSelf() no need to fully explain this. It simply removes our event listener and removes the smoke puff from the display stack.

Alright, so that makes our smoke move. Let’s write the code for the main class.

package
{ import flash.display.Stage;
	import flash.display.MovieClip;
	import flash.events.Event;
	import com.asgamer.graphics.Smokepuff;
	import flash.display.Sprite; public class Main extends Sprite
	{ public function Main() : void
		{
			addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
		} private function loop(e:Event) : void
		{
			var smokepuff:Smokepuff = new Smokepuff();
			smokepuff.x = 250;
			smokepuff.y = 250;
			stage.addChild(smokepuff);
		} } }

Okay breaking this down is extremely simple. We’re just creating an event listener to call loop on every enter frame like we did in Smokepuff. In the loop class we simply are creating a Smokepuff and positioning it at (250, 250) and adding it to the stage. From here our Smokepuff code will do everything on it’s own with a little help from garbage collection in the end.

Ready to see what it looks like?

The Flash plugin is required to view this object.

Awesome we’re done. Here’s the final source:
Making Smoke in Flash Source Code Zip Archive

分享到:
评论

相关推荐

    spi flash verilog simulation model仿真模型

    SPI Flash是一种常见的非易失性存储器,常用于嵌入式系统中,作为微控制器(MCU)的数据存储。在本资源包中,重点是针对Numonyx N25Q128系列的SPI Flash的Verilog仿真模型,这对于硬件设计者和验证工程师来说非常有...

    norflash-model.zip_norflash_norflash verilog_simulation_model_ve

    标题中的“norflash-model.zip_norflash_norflash verilog_simulation_model_ve”表明这是一个与NorFlash( NOR型闪存)相关的Verilog HDL(硬件描述语言)仿真模型。NorFlash是一种非易失性存储器技术,常用于微...

    Visual Simulation of Smoke

    在计算机图形学中,烟雾模拟是一个复杂而具有挑战性的课题。烟雾作为一种自然现象,其动力学特性高度复杂和紊乱,这些特性使得在计算机图形学领域中准确模拟烟雾的行为变得相当困难。然而,烟雾模拟不仅在影视特效和...

    QSPI_FLASH_MODEL.zip

    《QSPI FLASH在FPGA/ASIC开发中的Verilog模型详解》 在电子设计领域,FPGA(Field-Programmable Gate Array)和ASIC(Application-Specific Integrated Circuit)是两种常用的集成电路,它们在数字系统设计中扮演着...

    plant-simulation周金平 源代码_plantSimulation_plantsimulation_PlantSim

    《Plant Simulation:周金平教程解析》 Plant Simulation是一款强大的离散事件仿真软件,主要用于工业生产系统的模拟和优化。在工业工程、物流管理和制造系统设计等领域有着广泛的应用。本教程由专家周金平主讲,...

    Plant Simulation案例合计

    ### Plant Simulation 概述 **Plant Simulation** 是一款由西门子提供的专业软件工具,主要用于生产系统和过程的模拟与优化。它可以帮助企业通过构建数字模型来探索物流系统的特性和优化其性能,从而提高生产效率并...

    plant simulation基础培训教程(中文)

    Plant Simulation是一款面向对象的、图形化的、集成的建模和仿真工具,它允许用户对各种规模的工厂和生产线进行建模、仿真和优化,这包括大规模的跨国企业。Plant Simulation的系统结构和实施都遵循面向对象的原则,...

    Plant-Simulation安装教程

    Plant-Simulation安装教程

    library simulation

    library simulation library simulation library simulation library simulation library simulation library simulation library simulation library simulation library simulation library simulation

    西门子仿真Plant.Simulation.16.0.0.Full.Win64.part1

    西门子仿真Plant.Simulation.16.0.0是西门子公司推出的一款先进的仿真软件,主要用于对各种工业流程进行模拟和优化。该软件采用先进的建模和仿真技术,可以帮助工程师在实际投入生产之前,对各种可能的生产过程进行...

    Manufacturing Simulation with Plant Simulation and Simtalk

    《制造模拟与Plant Simulation及SimTalk》一书由Steffen Bangsow撰写,是一部针对制造业模拟领域的专业著作。本书不仅提供了丰富的理论知识,还包含了100个实用的示例,旨在帮助读者深入理解并掌握制造过程中的模拟...

    Tecnomatix Plant Simulation教学

    ### Tecnomatix Plant Simulation 教学:生产与物流仿真的深入解析 #### 一、Tecnomatix Plant Simulation 概述 Tecnomatix Plant Simulation 是一款由 Siemens 提供的专业生产与物流仿真软件。它可以帮助企业通过...

    Computer Simulation of Liquids 免费下载

    A first in its field, this book is both an introduction to computer simulation of liquids for upper level undergraduates and a how-to guide for specialists. The authors discuss the latest simulation ...

    LabVIEW Simulation Interface Toolkit 注册机

    LabVIEW Simulation Interface Toolkit 注册机

    Flow Simulation汉化

    Flow Simulation是一款专业的流体动力学仿真软件,广泛应用于工程设计和科研领域,它能够帮助用户在计算机上模拟和预测各种流体流动、热传递以及化学反应等现象。这款软件通常包含丰富的物理模型库,适用于机械工程...

    SingleLine_plantsimulation案例_plantSimulation_

    Plant Simulation是一款强大的仿真软件,主要用于工业生产系统的建模和优化。这个"SingleLine_plantsimulation案例"是一个适合初学者入门的教程,旨在帮助用户了解如何使用Plant Simulation进行基本的生产线模拟。 ...

    Aircraft control and simulation

    The updated revision of the well-respected book on analyzing aircraft performance, This Second Edition of the bestselling Aircraft Control and Simulation has been expanded and updated to include the ...

    Prosys_OPC_UA_Simulation_Server_UserManual.pdf

    OPC UA Simulation Server 用户手册 OPC UA Simulation Server 是一款功能强大的仿真服务器软件,用于模拟 OPC UA 服务器的行为。该软件提供了一个用户友好的界面,允许用户轻松地配置和控制仿真服务器的行为。 在...

Global site tag (gtag.js) - Google Analytics