<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Swingpant&#039;s Game Lab &#187; blendMode</title>
	<atom:link href="http://swingpants.com/tag/blendmode/feed/" rel="self" type="application/rss+xml" />
	<link>http://swingpants.com</link>
	<description>Swingpant&#039;s Code Nurdlings</description>
	<lastBuildDate>Wed, 08 Feb 2012 08:02:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='swingpants.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/4a88693aa17d6b5e1d453a6684bc1c68?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Swingpant&#039;s Game Lab &#187; blendMode</title>
		<link>http://swingpants.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://swingpants.com/osd.xml" title="Swingpant&#039;s Game Lab" />
	<atom:link rel='hub' href='http://swingpants.com/?pushpress=hub'/>
		<item>
		<title>AS3 Flamer Class :: Setting things on fire</title>
		<link>http://swingpants.com/2010/02/25/as3-flamer-class-setting-things-on-fire/</link>
		<comments>http://swingpants.com/2010/02/25/as3-flamer-class-setting-things-on-fire/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 12:14:49 +0000</pubDate>
		<dc:creator>swingpants</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[Effect]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Games]]></category>
		<category><![CDATA[bitmapdata]]></category>
		<category><![CDATA[blendMode]]></category>
		<category><![CDATA[convolution filter]]></category>
		<category><![CDATA[fire]]></category>
		<category><![CDATA[fire effect]]></category>
		<category><![CDATA[flamer]]></category>
		<category><![CDATA[flames]]></category>
		<category><![CDATA[paletteMap]]></category>
		<category><![CDATA[perlin noise]]></category>

		<guid isPermaLink="false">http://swingpants.com/?p=230</guid>
		<description><![CDATA[The Flamer Class is a quick and easy method to set things on fire. Throw some fuel (any display object) at the class and make it burn. While working on another project I needed to make some lightweight flames. I looked around, tried a bit of perlin noise, some convolution filters &#8211; then some PixelBender [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=swingpants.com&amp;blog=5703708&amp;post=230&amp;subd=flashlabs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>
The Flamer Class is a quick and easy method to set things on fire. Throw some fuel (any display object) at the class and make it burn.
</p>
<p>
While working on another project I needed to make some lightweight flames. I looked around, tried a bit of perlin noise, some convolution filters &#8211; then some PixelBender filtering &#8211; I wasn&#8217;t really happy with the results.
</p>
<p>
I found the excellent Saqoosha&#8217;s <a href="http://wonderfl.net/code/bffb3437de866ffdfcdd5015b1fba5ca37fff72a">Fire</a> on <a href="http://wonderfl.net">Wonderfl</a>.<br />
This demo had nearly the flicker and colour mapping that I was looking for. Rendering the perlin noise on each frame was causing a bit too much processor overhead for my purposes.<br />
Instead of rendering two perlin octaves and moving the layers against each other, I took two separate single octave perlin noise bitmaps and rotated one against the other while blending.<br />
This gives a nice effect and is very lightweight. With the Saqoosha method I was clocking at a steady 26fps, with my lightweight method I could get 90fps.
</p>
<p>
To get the flame hues I set up a gradient box, threw some colours at it, loaded those colours into an array which I then pushed to a palette map.
</p>
<p>
So how to use the Flamer class:</p>
<blockquote><p>
<strong><br />
import swingpants.effect.Flamer</p>
<p>var flamer:Flamer=new Flamer(display_object)<br />
addChild(flamer)</p>
<p>addEventListener(Event.ENTER_FRAME, enterFrameHandler)<br />
function enterFrameHandler(event:Event):void<br />
   {<br />
     flamer.update()<br />
   }<br />
</strong>
</p></blockquote>
<p>Your object will now be on fire. Feel naughty?
</p>
<p>You can set the render width and height and also set the direction of the flames by setting a point vector.</p>
<blockquote><p>
<strong><br />
var flamer:Flamer=new Flamer(display_object,render_width, render_height, flame_direction_point)<br />
addChild(flamer)</p>
<p>//The colour of the flames can be set with one of the presets (There are 4 at the moment &#8211; ORANGE_FLAME, BLUE_FLAME, YELLOW_FLAME, GREEN_FLAME &#8211; but I will be adding more)<br />
flamer.setFlameColour(Flamer.BLUE_FLAME) </p>
<p>//Direction can be set on the fly:<br />
flamer.setFlameDirection(direction_point)<br />
</strong>
</p></blockquote>
<p>Here is a demo of a pure code use of the Flamer: <a href="http://www.swingpantsflash.com/flamer/Flamer.html">The Flaming Vortex</a>. You can click on the flash to initiate an explosion, and pressing space will change the colour. Have a play:</p>
<div id="attachment_232" class="wp-caption aligncenter" style="width: 360px"><a href="http://www.swingpantsflash.com/flamer/Flamer.html"><img src="http://flashlabs.files.wordpress.com/2010/02/flaming_sun.jpg?w=655" alt="Flaming Sun" title="flaming_sun"   class="size-full wp-image-232" /></a><p class="wp-caption-text">Flamer Class. The flaming vortex demo</p></div>
<p>This next demo is an example of throwing a movieclip/sprite at the Flamer class. Don&#8217;t laugh, I quite literally spent 10 minutes putting the anims together then threw them at the Flamer. Click on Flash to change colour and object.<br />
<div id="attachment_233" class="wp-caption aligncenter" style="width: 360px"><a href="http://www.swingpantsflash.com/flamer/FlaTestFlamer.html"><img src="http://flashlabs.files.wordpress.com/2010/02/flaming_car.jpg?w=655" alt="Flaming Car" title="flaming_car"   class="size-full wp-image-233" /></a><p class="wp-caption-text">Flamer Class Demo. Help, my car is on fire</p></div></p>
<p>Lots of fun can be had by throwing different animations at the Flamer. Control some with your mouse/keys. Become a twisted fire starter.</p>
<p>The Flamer class could do with a few more features, but is a pretty good start. The speed is pretty good, I&#8217;m happy to receive any improvement recommendations.</p>
<p>I have packed the Flamer class and demos up in a zip if you want to have a play:<br />
DOWNLOAD: <a href="http://www.swingpantsflash.com/flamer/FlamerClass.zip">Flamer Class and Demos</a></p>
<p>DEMO #1: <a href="http://www.swingpantsflash.com/flamer/Flamer.html">Flaming Vortex</a><br />
DEMO #2: <a href="http://www.swingpantsflash.com/flamer/FlaTestFlamer.html">Burning Movieclips</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/flashlabs.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/flashlabs.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/flashlabs.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/flashlabs.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/flashlabs.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/flashlabs.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/flashlabs.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/flashlabs.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/flashlabs.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/flashlabs.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/flashlabs.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/flashlabs.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/flashlabs.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/flashlabs.wordpress.com/230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=swingpants.com&amp;blog=5703708&amp;post=230&amp;subd=flashlabs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://swingpants.com/2010/02/25/as3-flamer-class-setting-things-on-fire/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cebf29489913586137c5bdad0414c88?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">swingpants</media:title>
		</media:content>

		<media:content url="http://flashlabs.files.wordpress.com/2010/02/flaming_sun.jpg" medium="image">
			<media:title type="html">flaming_sun</media:title>
		</media:content>

		<media:content url="http://flashlabs.files.wordpress.com/2010/02/flaming_car.jpg" medium="image">
			<media:title type="html">flaming_car</media:title>
		</media:content>
	</item>
		<item>
		<title>Gradients and masks in actionscript</title>
		<link>http://swingpants.com/2009/04/30/gradients-and-masks-in-actionscript/</link>
		<comments>http://swingpants.com/2009/04/30/gradients-and-masks-in-actionscript/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 09:24:55 +0000</pubDate>
		<dc:creator>swingpants</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Alpha]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[blendMode]]></category>
		<category><![CDATA[cacheAsBitmap]]></category>
		<category><![CDATA[Gradient]]></category>
		<category><![CDATA[Layer]]></category>
		<category><![CDATA[Masks]]></category>

		<guid isPermaLink="false">http://swingpants.com/?p=124</guid>
		<description><![CDATA[Quick post to describe how to apply a gradient mask to a display object in AS3 (&#38; AS2). #1 Put your gradient mask on the stage &#8211; lets call it gmask #2 Put the object to be masked on the stage. #3 Set both the mask and the &#8216;object to be masked&#8217; to cacheAsBitmap #4 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=swingpants.com&amp;blog=5703708&amp;post=124&amp;subd=flashlabs&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Quick post to describe how to apply a gradient mask to a display object in AS3 (&amp; AS2).</p>
<p><strong>#1</strong> Put your gradient mask on the stage &#8211; lets call it gmask<br />
<strong>#2</strong> Put the object to be masked on the stage.<br />
<strong>#3</strong> Set both the mask and the &#8216;object to be masked&#8217; to cacheAsBitmap<br />
<strong>#4</strong> Apply the mask to the object</p>
<p><strong>In #AS3</strong><br />
  <em>gmask.cacheAsBitmap = true<br />
  obj_to_be_masked.cacheAsBitmap = true<br />
  obj_to_be_masked.mask =gmask</em></p>
<p><strong>In #AS2</strong><br />
  <em>gmask.cacheAsBitmap = true<br />
  obj_to_be_masked.cacheAsBitmap = true<br />
  obj_to_be_masked.setMask(mask)</em></p>
<p>It really is as simple as this.<br />
<strong><em>Note to designers</em></strong>: Gradient masks can&#8217;t obviously be done directly from the IDE (see below), but these  three lines can be placed on the timeline if so desired.</p>
<p>To put a gradient mask on dynamic text you will need to place the text within a container (movieclip/sprite) and mask that. </p>
<p>The object to be masked can also contain animation, text or video though this will require a bit more processor as the bitmap will need to redraw on each frame. Often this is well worth it as the effect can be great.</p>
<p><strong>There is a way of achieving this same effect with no code at all and here it is:</strong></p>
<p><strong>#1</strong> Put your gradient mask on the stage &#8211; lets call it gmask<br />
<strong>#2</strong> Put the object to be masked on the stage.<br />
<strong>#3</strong> Put both of these items into a movieclip/sprite (the container) making sure the mask is on a layer above the object<br />
<strong>#4</strong> Give the mask a blend mode of &#8216;Alpha&#8217;<br />
<strong>#5</strong> Give the &#8216;container&#8217; a blend mode of &#8216;Layer&#8217;</p>
<p>And there you have it. Gradient masking achieved with blendModes and absolutely no code.</p>
<p><strong>Benchmarking the two gradient mask methods</strong>:<br />
I used each method to mask an embedded video &#8211; then placed an instance on the display list and ran at varying frame rates.<br />
Initially there was negligible difference between the code and blend mask methods. I ramped up the FPS to 120 and put four instances of the video on screen. With this set up the code method (cacheAsBitmap) was up to <strong>4%</strong> faster than the blendMode Mask method.</p>
<p>Conclusion: The code method is faster but very marginally. If you are desperate for a bit of extra juice go with code.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/flashlabs.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/flashlabs.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/flashlabs.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/flashlabs.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/flashlabs.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/flashlabs.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/flashlabs.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/flashlabs.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/flashlabs.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/flashlabs.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/flashlabs.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/flashlabs.wordpress.com/124/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/flashlabs.wordpress.com/124/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/flashlabs.wordpress.com/124/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=swingpants.com&amp;blog=5703708&amp;post=124&amp;subd=flashlabs&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://swingpants.com/2009/04/30/gradients-and-masks-in-actionscript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/1cebf29489913586137c5bdad0414c88?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">swingpants</media:title>
		</media:content>
	</item>
	</channel>
</rss>
