<?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/"
	>

<channel>
	<title>GuShH&#039;s DevBlog &#187; Game Development</title>
	<atom:link href="http://gushh.net/blog/?tag=gamedev&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://gushh.net/blog</link>
	<description>This blog is about software, electronics engineering and game development.</description>
	<lastBuildDate>Tue, 24 Jan 2012 00:31:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>(PB) Loading Assets, the simple way.</title>
		<link>http://gushh.net/blog/loading-assets-simple-way/</link>
		<comments>http://gushh.net/blog/loading-assets-simple-way/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 00:29:27 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[asset]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[loading files]]></category>
		<category><![CDATA[purebasic]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=1284</guid>
		<description><![CDATA[Intro Assets are an essential part of most games, how you manage them determines whether you spend more time working on them than dealing with them. For small to medium games, loading an entire directory and having it referenced to a Map is the ideal solution. It&#8217;s both flexible and simple. The following code allows [...]]]></description>
			<content:encoded><![CDATA[<h2>Intro</h2>
<p>Assets are an essential part of most games, how you manage them determines whether you spend more time working on them than dealing with them.</p>
<p>For small to medium games, loading an entire directory and having it referenced to a Map is the ideal solution. It&#8217;s both flexible and simple.</p>
<h4>The following code allows you to do just this:</h4>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Prototype</span>.i LOAD_DIRECTORY_CALLBACK<span style="color: #000066;">&#40;</span> Map Assets.i<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, directory.s, extension.s, name.s, userDefined.i <span style="color: #000066;">=</span> #Null <span style="color: #000066;">&#41;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i LoadDirectory<span style="color: #000066;">&#40;</span> Map assets.i<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, directory.s, extension.s, <span style="color: #000066;">*</span>callback.LOAD_DIRECTORY_CALLBACK, userDefined.i <span style="color: #000066;">=</span> #Null <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.i dir <span style="color: #000066;">=</span> <span style="color: #0000ff;">ExamineDirectory</span><span style="color: #000066;">&#40;</span> #PB_Any, directory, <span style="color: #009900;">&quot;*&quot;</span> <span style="color: #000066;">+</span> extension <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">IsDirectory</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">Define</span>.i count <span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.s name <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;&quot;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">While</span> <span style="color: #0000ff;">NextDirectoryEntry</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">DirectoryEntryType</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> #PB_DirectoryEntry_File
				name <span style="color: #000066;">=</span> <span style="color: #0000ff;">DirectoryEntryName</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span><span style="color: #ff0000; font-style: italic;">;</span>
				assets<span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">ReplaceString</span><span style="color: #000066;">&#40;</span> name, extension, <span style="color: #009900;">&quot;&quot;</span> <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>callback<span style="color: #000066;">&#40;</span> assets<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, directory, extension, name, userDefined <span style="color: #000066;">&#41;</span><span style="color: #ff0000; font-style: italic;">;LoadSound( #PB_Any, directory + &quot;\&quot; + name )</span>
				count <span style="color: #000066;">+</span> <span style="color: #CC0000;">1</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">Wend</span>
&nbsp;
		<span style="color: #0000ff;">FinishDirectory</span><span style="color: #000066;">&#40;</span> dir <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> count
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>To use this code you must define a procedure of your own, this procedure is going to be called on each file to be loaded; you&#8217;ll have to load and process the file in this function.</p>
<h4>Example use:</h4>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Global</span> NewMap sprite.i<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">Procedure</span>.i callback_loadsprites<span style="color: #000066;">&#40;</span> Map Assets.i<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, directory.s, extension.s, name.s, userDefined.i <span style="color: #000066;">=</span> #Null <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">LoadSprite</span><span style="color: #000066;">&#40;</span> #PB_Any, directory <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;\&quot;</span> <span style="color: #000066;">+</span> name, userDefined <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
LoadDirectory<span style="color: #000066;">&#40;</span> sprite<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, <span style="color: #009900;">&quot;sprites&quot;</span>, <span style="color: #009900;">&quot;.png&quot;</span>, @callback_loadsprites<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span></pre></div></div>

<p>The example will attempt to scan through the directory &#8220;sprites&#8221;, it will execute your callback on each png file it finds inside the aforementioned directory, furthermore it&#8217;ll reference the filename (without extension) to the sprite() Map, so when you need a handle for the sprite called &#8220;fire.png&#8221; you&#8217;d just use sprite(&#8220;fire&#8221;) to obtain it.</p>
<p>Since the files are referenced to a Map by their actual name, you could easily implement a scripting system or any other dynamic management solution for your assets without much hassle.</p>
<blockquote><p>An interesting part of the code is the return value, it&#8217;s actually the number of assets found (not the ones loaded, since your callback could choose not to load a certain file, for instance).</p></blockquote>
<p>There are several limitations to this simple implementation, which is why I mentioned &#8220;small games&#8221; &#8211; There is no directory recursion, no advanced filtering options, no way to parallel the process on a separate thread and there&#8217;s no error handling at the moment.</p>
<p>However, it&#8217;s still very useful and I highly recommend you try it out, while it&#8217;s not a novel aproach, it&#8217;s always been the method I used to load my assets and it just works.</p>
<p>Have fun!</p>
<g:plusone href='http://gushh.net/blog/loading-assets-simple-way/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/loading-assets-simple-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(FREE) Game sprites &#124; Fire 1</title>
		<link>http://gushh.net/blog/free-game-sprites-fire-1/</link>
		<comments>http://gushh.net/blog/free-game-sprites-fire-1/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 03:18:58 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[fire sprite]]></category>
		<category><![CDATA[free game resources]]></category>
		<category><![CDATA[indie game development]]></category>
		<category><![CDATA[light fire sprites]]></category>
		<category><![CDATA[sprite sheet]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=998</guid>
		<description><![CDATA[Intro: Light fire sprite sheet, ideal for filler or part of a composition. Complete with all frames. Specs: 128&#215;128 38 frames Alpha channel, PNG &#160; The goodies: Notes: Take a look at the legal notes here. Commercial use is prohibited. More to come&#8230;]]></description>
			<content:encoded><![CDATA[<h2>Intro:</h2>
<p>Light fire sprite sheet, ideal for filler or part of a composition. Complete with all frames.</p>
<h2>Specs:</h2>
<ul>
<li>128&#215;128</li>
<li>38 frames</li>
<li>Alpha channel, PNG</li>
</ul>
<p>&nbsp;</p>
<h2>The goodies:</h2>
<div>
<dl id="attachment_957"></dl>
</div>
<div id="attachment_1000" class="wp-caption aligncenter" style="width: 310px"><a href="http://gushh.net/blog/wp-content/uploads/2011/06/fire_1_38_128.png"><img class="size-medium wp-image-1000" title="fire_1_38_128" src="http://gushh.net/blog/wp-content/uploads/2011/06/fire_1_38_128-300x300.png" alt="" width="300" height="300" /></a><p class="wp-caption-text">Neat little fire</p></div>
<h2>Notes:</h2>
<p>Take a look at the legal notes <a title="(FREE) Game sprites | Explosion 1" href="http://gushh.net/blog/free-game-sprites-explosion-1/" target="_blank">here</a>. <strong>Commercial use is prohibited</strong>.</p>
<p>More to come&#8230;</p>
<g:plusone href='http://gushh.net/blog/free-game-sprites-fire-1/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/free-game-sprites-fire-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(FREE) Game sprites &#124; Explosion 1</title>
		<link>http://gushh.net/blog/free-game-sprites-explosion-1/</link>
		<comments>http://gushh.net/blog/free-game-sprites-explosion-1/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 09:12:51 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[C4]]></category>
		<category><![CDATA[explosion sprite]]></category>
		<category><![CDATA[free explosion sprites]]></category>
		<category><![CDATA[free game graphics]]></category>
		<category><![CDATA[free sprites]]></category>
		<category><![CDATA[fx]]></category>
		<category><![CDATA[game design]]></category>
		<category><![CDATA[prototype graphics]]></category>
		<category><![CDATA[sparks]]></category>
		<category><![CDATA[sprite sheet]]></category>
		<category><![CDATA[volumetric smoke]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=915</guid>
		<description><![CDATA[Intro: The following is a volumetric explosion sprite sheet, one of many left over from past work. You may use them for private or freeware (open source only) projects. Commercial use is prohibited, please contact me regarding licensing or custom work. Specs: There are 38 frames. Each frame is 128&#215;128 and the complete sheet contains [...]]]></description>
			<content:encoded><![CDATA[<h2>Intro:</h2>
<p>The following is a volumetric explosion sprite sheet, one of many left over from past work. You may use them for private or freeware (open source only) projects. Commercial use is prohibited, please <a title="Contact Me" href="http://gushh.net/blog/contact/" target="_blank">contact me</a> regarding licensing or custom work.</p>
<h2>Specs:</h2>
<p>There are 38 frames. Each frame is 128&#215;128 and the complete sheet contains an alpha channel, the grid is centered but it hasn&#8217;t been packed; as you can see there&#8217;s a lot of wasted space. This is however a &#8220;sane&#8221; way of sharing the sprites, otherwise I would have to provide my own format specifications for the metadata, packer, etc.</p>
<p>This way you can split them and pack them however you want into whatever format you wish. These are however quite usable in their current form.</p>
<h2>The goodies:</h2>
<div id="attachment_916" class="wp-caption aligncenter" style="width: 310px"><a href="http://gushh.net/blog/wp-content/uploads/2011/06/explosion_1_38_128.png"><img class="size-medium wp-image-916 " title="explosion_1_38_128" src="http://gushh.net/blog/wp-content/uploads/2011/06/explosion_1_38_128-300x300.png" alt="" width="300" height="300" /></a><p class="wp-caption-text">A simple volumetric explosion</p></div>
<div id="attachment_917" class="wp-caption aligncenter" style="width: 310px"><a href="http://gushh.net/blog/wp-content/uploads/2011/06/explosion_1_38_128_corrected.png"><img class="size-medium wp-image-917 " title="explosion_1_38_128_corrected" src="http://gushh.net/blog/wp-content/uploads/2011/06/explosion_1_38_128_corrected-300x300.png" alt="Volumetric explosion sprite sheet" width="300" height="300" /></a><p class="wp-caption-text">A simple volumetric explosion, corrected levels, saturation, etc.</p></div>
<p>&nbsp;</p>
<h2>Misc:</h2>
<p>The corrected version was not exactly proofed, there are a few artifacts due to the processing, however if you&#8217;re going to use any sort of scaling filter these shouldn&#8217;t be a problem.</p>
<p>As you probably noticed the particles were rendered using a black background, mostly because of the high amounts of smoke involved; white or neutral would&#8217;ve been problematic.</p>
<h2>Footer:</h2>
<p>It&#8217;s no secret that these are leftovers, but they&#8217;re perfectly good sprites &#8212; they just didn&#8217;t make it due to time constraints.</p>
<p>I cannot discuss which title they were meant for though, but I can tell you there&#8217;s more of them.</p>
<p>The actual image data contains a disclaimer, it&#8217;s hidden by the alpha channel. I mention this because I take it seriously, you may not profit from my work unless &#8220;I&#8221; profit from your work (It&#8217;s only fair right?).</p>
<p>Other than that feel free to use them, even as place-holders. And of course, if you&#8217;d like to share some of your handy work, feel free to <a title="Contact Me" href="http://gushh.net/blog/contact/" target="_blank">contact me</a>.</p>
<p>I&#8217;ll probably post more freebies throughout the week.</p>
<p>Cheers.</p>
<g:plusone href='http://gushh.net/blog/free-game-sprites-explosion-1/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/free-game-sprites-explosion-1/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Spaceship Generator!</title>
		<link>http://gushh.net/blog/spaceship-generator/</link>
		<comments>http://gushh.net/blog/spaceship-generator/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 20:47:10 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[pixel spaceships]]></category>
		<category><![CDATA[procedural]]></category>
		<category><![CDATA[spaceship generator]]></category>
		<category><![CDATA[spore]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=314</guid>
		<description><![CDATA[I&#8217;ve been working on implementing a content generator and mutator, this particular version was based on the Pixel Spaceships work. This was indeed my first goal. The next logical step is to start separating the various parts of the code and begin to implement various means of generating content, adding noise based on a map/pattern [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on implementing a content generator and mutator, this particular version was based on the Pixel Spaceships work. This was indeed my first goal.</p>
<div id="attachment_315" class="wp-caption aligncenter" style="width: 310px"><a href="http://gushh.net/blog/wp-content/uploads/2010/06/spaceshipgenv1.png"><img class="size-medium wp-image-315" title="spaceshipgenv1" src="http://gushh.net/blog/wp-content/uploads/2010/06/spaceshipgenv1-300x218.png" alt="" width="300" height="218" /></a><p class="wp-caption-text">One Iteration based on a base pattern gives us many ships to choose from.</p></div>
<p>The next logical step is to start separating the various parts of the code and begin to implement various means of generating content, adding noise based on a map/pattern as well as being able to mix different patterns to change the outcome. Another step in the process is to allow the use of arbitrarily sized patterns.</p>
<p>With just a few modifications to the base pattern we can generate all kinds of content, we then choose the one we like the most and select it&#8217;s pattern as the new base design for future mutations. The possibilities are endless!</p>
<p>Generating procedural content is nothing new, but it sure is exciting! &#8212; And it&#8217;s always a challenge to optimize and evolve this type of code.</p>
<p>Hopefully I&#8217;ll come up with something usable in the near future.</p>
<g:plusone href='http://gushh.net/blog/spaceship-generator/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/spaceship-generator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Animation lib</title>
		<link>http://gushh.net/blog/animation-lib/</link>
		<comments>http://gushh.net/blog/animation-lib/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 21:43:43 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[clipsprite]]></category>
		<category><![CDATA[Game Development]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[purebasic]]></category>
		<category><![CDATA[sprite]]></category>
		<category><![CDATA[sprite sheet]]></category>
		<category><![CDATA[timelapse]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=192</guid>
		<description><![CDATA[Dependent on the time-lapse lib, the animation code provides you with several count methods to manipulate your animations in an easy and comprehensible way. If you add a sprite atlas library (I&#8217;ll share later) you&#8217;ll be able to manipulate sprites with animation in quite a flexible way without too much hassle. The idea is to [...]]]></description>
			<content:encoded><![CDATA[<p>Dependent on the <a href="http://gushh.net/blog/2009/08/05/timelapse-lib/">time-lapse</a> lib, the animation code provides you with several count methods to manipulate your animations in an easy and comprehensible way.</p>
<p>If you add a sprite atlas library (I&#8217;ll share later) you&#8217;ll be able to manipulate sprites with animation in quite a flexible way without too much hassle.</p>
<p>The idea is to encapsulate the animation functionality in such a way that it makes it easy to work with. You have the ability to start, stop, pause, change speed, etc. You can create animations that range from any frame to any frame and that can animate in many ways such as sequential (loop), play-once and ping-pong (back and forth, or rather the inverse). By making use of the time-lapse library we can easily create time-based animation.</p>
<p><span id="more-192"></span></p>
<p>The base code:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">;##############################################################################</span>
<span style="color: #ff0000; font-style: italic;">;$$$	file: Animation.pb - date: 05:05 p.m. 06/08/2009			$$$</span>
<span style="color: #ff0000; font-style: italic;">;$$$	author: Gustavo Julio Fiorenza (info@gushh.net || info@gushh.com.ar)	$$$</span>
<span style="color: #ff0000; font-style: italic;">;$$$					aka: gushh, dagcrack.			$$$</span>
<span style="color: #ff0000; font-style: italic;">;$$$ 	description: provides several count modes for animation purposes	$$$</span>
<span style="color: #ff0000; font-style: italic;">;##############################################################################</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EnableExplicit</span>
<span style="color: #000066; font-weight: bold;">XIncludeFile</span> <span style="color: #009900;">&quot;TimeLapse.pb&quot;</span> <span style="color: #ff0000; font-style: italic;">; Used for timing.</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Structure</span> ANIMATION
	<span style="color: #000066;">*</span>timer.TIMELAPSE	<span style="color: #ff0000; font-style: italic;">; The timer's speed is &quot;per frame&quot;, use the Get/SetLength functions to overcome this.</span>
	frame_max.i		<span style="color: #ff0000; font-style: italic;">; Maximum global frame</span>
	frame_min.i		<span style="color: #ff0000; font-style: italic;">; Minimum global frame</span>
	frame_now.i		<span style="color: #ff0000; font-style: italic;">; Current local frame</span>
	mode.i			<span style="color: #ff0000; font-style: italic;">; The animation mode (loop, play once, ping-pong, etc).</span>
	status.i		<span style="color: #ff0000; font-style: italic;">; Internal var used for keeping track of the animation &quot;status&quot;. It's used as a bool.</span>
	is_playing.i		<span style="color: #ff0000; font-style: italic;">; Used to determine whether the animation is playing or not.</span>
<span style="color: #000066; font-weight: bold;">EndStructure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Enumeration</span> <span style="color: #CC0000;">1</span>
	#ANIMATION_LOOP
	#ANIMATION_PLAYONCE
	#ANIMATION_PINGPONG
<span style="color: #000066; font-weight: bold;">EndEnumeration</span>
&nbsp;
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationCreate<span style="color: #000066;">&#40;</span> Speed.i, MinFrame.i, MaxFrame.i, CurrentFrame.i <span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span>, Mode.i <span style="color: #000066;">=</span> #ANIMATION_LOOP, <span style="color: #000066;">*</span>callback.i <span style="color: #000066;">=</span> #Null <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.ANIMATION <span style="color: #000066;">*</span>this <span style="color: #000066;">=</span> <span style="color: #0000ff;">AllocateMemory</span><span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span>ANIMATION<span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066; font-weight: bold;">With</span> <span style="color: #000066;">*</span>this
			<span style="color: #000066;">\</span>timer		<span style="color: #000066;">=</span> TimeLapseCreate<span style="color: #000066;">&#40;</span> Speed, <span style="color: #000066;">*</span>callback, <span style="color: #000066;">*</span>this <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; We're passing this instance as the timer's user-data, useful in callbacks.</span>
			<span style="color: #000066;">\</span>frame_max 	<span style="color: #000066;">=</span> MaxFrame
			<span style="color: #000066;">\</span>frame_min	<span style="color: #000066;">=</span> MinFrame
			<span style="color: #000066;">\</span>frame_now	<span style="color: #000066;">=</span> MinFrame <span style="color: #000066;">+</span> CurrentFrame
			<span style="color: #000066;">\</span>mode 		<span style="color: #000066;">=</span> Mode
			<span style="color: #000066;">\</span>status		<span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span>
			<span style="color: #000066;">\</span>is_playing	<span style="color: #000066;">=</span> #True
		<span style="color: #000066; font-weight: bold;">EndWith</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this
&nbsp;
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationDestroy<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>timer
			TimeLapseDestroy<span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>timer<span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #0000ff;">FreeMemory</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>this<span style="color: #000066;">&#41;</span>
		<span style="color: #000066;">*</span>this <span style="color: #000066;">=</span> #Null
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this
&nbsp;
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationUpdate<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>is_playing
			<span style="color: #000066; font-weight: bold;">If</span> TimeLapseUpdate<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>timer <span style="color: #000066;">&#41;</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">Select</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>mode
&nbsp;
					<span style="color: #000066; font-weight: bold;">Case</span> #ANIMATION_LOOP
&nbsp;
						<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">+</span> <span style="color: #CC0000;">1</span>
&nbsp;
						<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">&gt;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_max
							<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_min
						<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">Case</span> #ANIMATION_PINGPONG
&nbsp;
						<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>status
&nbsp;
							<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">-</span> <span style="color: #CC0000;">1</span>
&nbsp;
							<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">&lt;</span> <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_min
								<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>status <span style="color: #000066;">=</span> #True <span style="color: #000066;">-</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>status
							<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
						<span style="color: #000066; font-weight: bold;">Else</span>
&nbsp;
							<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">+</span> <span style="color: #CC0000;">1</span>
&nbsp;
							<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">=&gt;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_max
								<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>status <span style="color: #000066;">=</span> #True <span style="color: #000066;">-</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>status
							<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
						<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">Case</span> #ANIMATION_PLAYONCE
&nbsp;
						<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>status
							<span style="color: #ff0000; font-style: italic;">; status is set to one, this means we already played the animation.</span>
						<span style="color: #000066; font-weight: bold;">Else</span>
&nbsp;
							<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">+</span> <span style="color: #CC0000;">1</span>
&nbsp;
							<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">=&gt;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_max
								<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>status <span style="color: #000066;">=</span> #True <span style="color: #000066;">-</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>status
							<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
						<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">EndSelect</span>	
&nbsp;
				<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> #True <span style="color: #ff0000; font-style: italic;">; always return true unless you want to invalidate the update call!</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>The helper functions:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationGetCurrentFrame<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">-</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_min
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationSetCurrentFrame<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION, Frame.i <span style="color: #000066;">&#41;</span>
	<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>Frame <span style="color: #000066;">-</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_min<span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationGetTotalFrames<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_max <span style="color: #000066;">-</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_min<span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationGetMode<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>mode
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationSetMode<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION, NewMode.i <span style="color: #000066;">&#41;</span>
	<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>mode <span style="color: #000066;">=</span> NewMode
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationGetSpeed<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> TimeLapseGet<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>timer <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationSetSpeed<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION, Speed.i <span style="color: #000066;">&#41;</span>
	TimeLapseSet<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>timer, Speed <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationPlay<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
	<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>is_playing	<span style="color: #000066;">=</span> #True
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationPause<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
	<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>is_playing	<span style="color: #000066;">=</span> #False
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationStop<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
	<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>is_playing	<span style="color: #000066;">=</span> #False
	<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_now		<span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>frame_min
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationReset<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
	AnimationStop<span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>this<span style="color: #000066;">&#41;</span>
	AnimationPlay<span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>this<span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationGetLength<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> AnimationGetTotalFrames<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this <span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> AnimationGetSpeed<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AnimationSetLength<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.ANIMATION, NewLength.i <span style="color: #000066;">&#41;</span>
	AnimationSetSpeed<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this, NewLength <span style="color: #000066;">/</span> AnimationGetTotalFrames<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>Thanks to the base lib, you can also use callbacks, this are useful for executing events on known frames (say you&#8217;re writing a game and you want a sound to be played at frame 12 from the jumping cycle&#8230; easy!)</p>
<p>A minimal example:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Define</span>.ANIMATION <span style="color: #000066;">*</span>anim
&nbsp;
<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">OpenConsole</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
	<span style="color: #000066;">*</span>anim <span style="color: #000066;">=</span> AnimationCreate<span style="color: #000066;">&#40;</span> <span style="color: #CC0000;">250</span>, <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">9</span>, <span style="color: #CC0000;">0</span>, #ANIMATION_PINGPONG <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>anim
		<span style="color: #000066; font-weight: bold;">Repeat</span>
			<span style="color: #000066; font-weight: bold;">If</span> AnimationUpdate<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>anim <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; the reason frame 0 is not seen in the first print is because we update before we display.</span>
				<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">Str</span><span style="color: #000066;">&#40;</span> AnimationGetCurrentFrame<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>anim <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
			<span style="color: #0000ff;">Delay</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Until</span> <span style="color: #0000ff;">Inkey</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #0000ff;">Chr</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">27</span><span style="color: #000066;">&#41;</span>
&nbsp;
		AnimationDestroy<span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>anim<span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #0000ff;">CloseConsole</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndIf</span></pre></div></div>

<p><em>A somewhat bloated example with callbacks can be found in <a href="http://gushh.net/dev/?file=pb/animation_example2.pb">here</a>.</em></p>
<p>The playback functionality could be extended, however I found little need for other methods &#8212; That&#8217;s basically my excuse for &#8220;I ran out of ideas&#8221; &#8212; One thing I&#8217;d do is decouple the &#8220;play once&#8221; functionality from the playing mode, so essentially you&#8217;d be able to play a loop or ping-pong animation just once.</p>
<p>That&#8217;s pretty much it. Once again, this is trivial code but it&#8217;s a must and I&#8217;m sure someone will benefit from it. </p>
<p>The only reason I didn&#8217;t post a graphical example is because you need a way of dealing with sprite sheets and that&#8217;s the job for yet another library. Should you use the sprite library, you&#8217;d still need to feed the ClipSprite() function with meaningful data, there is no point in doing it by hand. That said, I&#8217;ll post the &#8220;sprite atlas&#8221; library tomorrow, hopefully.</p>
<p>Cheers</p>
<g:plusone href='http://gushh.net/blog/animation-lib/'></g:plusone>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/animation-lib/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: gushh.net @ 2012-02-09 07:18:33 by W3 Total Cache -->
