<?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>ShiVa 3D</title>
	<atom:link href="http://www.shivaengine.com/developer/feed" rel="self" type="application/rss+xml" />
	<link>http://www.shivaengine.com/developer</link>
	<description>ShiVa developers will find here all the materials needed to create amazing games and web3D applications...</description>
	<lastBuildDate>Sun, 28 Apr 2013 15:19:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Android Plugin Development with Java and C++</title>
		<link>http://www.shivaengine.com/developer/2454-android-plugin-development-with-java-and-c</link>
		<comments>http://www.shivaengine.com/developer/2454-android-plugin-development-with-java-and-c#comments</comments>
		<pubDate>Mon, 28 Jan 2013 23:47:01 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Export]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2454</guid>
		<description><![CDATA[Starting with ShiVa 1.9.2 and the Authoring Tool 1.4, we greatly improved Android plugin development. Include JAR files in plugins and create self-contained plugins in C/C++ and Java code for Android with ShiVa!]]></description>
			<content:encoded><![CDATA[<h2>Easier plugin development for Android</h2>
<p>Starting with ShiVa 1.9.2 and the Authoring Tool 1.4, we have greatly improved Android plugin development. It is now possible to include JAR files in plugins and also in the &#8220;Additional Files&#8221; tab of the UAT. We added a Java bridge to make plugins communicate much more easily with Java and the Activities through JNI. In a nutshell, you can now create self-contained plugins (C/C++ and Java code) for Android with ShiVa.</p>
<h2>Plugin Creation in ShiVa</h2>
<p>Your new plugin workflow starts inside ShiVa. Create a new Plugin (Data Explorer > Plugins).</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/shivacreate1.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/shivacreate1.png" alt="" title="shivacreate1" width="370" height="329" class="alignnone size-full wp-image-2455" /></a></p>
<p>For this tutorial, we are going to create an example plugin called ToastLite. Our plugin will only contain one function: <code>ToastLite.show ( sText )</code>, which simply shows a Java label.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/shivafunction2.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/shivafunction2-600x436.png" alt="" title="shivafunction2" width="600" height="436" class="alignnone size-large wp-image-2457" /></a></p>
<p>We will call that function in our game when pressing a HUD button.</p>
<h2>Building the Bridge with Visual Studio</h2>
<p>Open the Windows Plugin by double-clicking on the plugin in ShiVa. Go to the Settings gear in the &#8220;Windows&#8221; line and select &#8220;Open Project&#8221;. The Visual Studio Solution will open.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/openwin.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/openwin-600x386.png" alt="" title="openwin" width="600" height="386" class="alignnone size-large wp-image-2494" /></a></p>
<p>In the <code>Plugin.h</code> file, add this:</p>
<pre style="padding-top:10px; padding-bottom:10px; background-color:#ccc;">virtual void SetJavaVM ( void* _pJavaVM );
void *pJavaVM;
</pre>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/vsplugH.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/vsplugH-600x406.png" alt="" title="vsplugH" width="600" height="406" class="alignnone size-large wp-image-2466" /></a></p>
<p>In the <code>Plugin.cpp</code> file, add that:</p>
<pre style="padding-top:10px; padding-bottom:10px; background-color:#ccc;">void ToastLite::SetJavaVM ( void* _pJavaVM )
{
	pJavaVM = _pJavaVM ;
}</pre>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/vsplugC.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/vsplugC-600x413.png" alt="" title="vsplugC" width="600" height="413" class="alignnone size-large wp-image-2467" /></a></p>
<p>In your <code><em>$api</em>.cpp</code> file (ex: ToastLite.cpp), add:</p>
<pre style="padding-top:10px; padding-bottom:10px; background-color:#ccc;">#if defined(__ANDROID__)
	#include &lt;jni.h&gt;

	static JNIEnv *ToastLite_GetJNIEnv ( )
	{
		JNIEnv *pJNIEnv ;

		if ( ToastLite::GetInstance ( )->pJavaVM
		&#038;&#038; ( ((JavaVM*)(ToastLite::GetInstance ( )->pJavaVM))->GetEnv (
		(void**) &#038;pJNIEnv, JNI_VERSION_1_4 )
		>= 0 ) )
		{
			return pJNIEnv ;
		}
		return NULL ;
	}
#endif</pre>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/vstoastlite1.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/vstoastlite1-600x441.png" alt="" title="vstoastlite1" width="600" height="441" class="alignnone size-large wp-image-2468" /></a></p>
<p>In the same file, in your Lua-to-C Callback <code>int Callback_ToastLite_show ( int _iInCount, const S3DX::AIVariable *_pIn, S3DX::AIVariable *_pOut )</code>,<br />
call your Java static functions <code>package: com.stonetrip.toastlite, class: ToastLite, function: ToastLite_Show (String)</code> by adding the following code below:</p>
<pre style="padding-top:10px; padding-bottom:10px; background-color:#ccc;">JNIEnv *pJNIEnv = ToastLite_GetJNIEnv ( ) ;
jclass pJNIClass = pJNIEnv->FindClass ( "com/stonetrip/toastlite/LibToastLite" ) ;
jmethodID pJNIMethodID = pJNIEnv->GetStaticMethodID ( pJNIClass,
"ToastLite_Show", "(Ljava/lang/String;)V" ) ;

jstring _sText = pJNIEnv->NewStringUTF ( sText.GetStringValue ( ) ) ;
pJNIEnv->CallStaticVoidMethod ( pJNIClass, pJNIMethodID, _sText ) ;
</pre>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/vsToastC3.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/vsToastC3-600x449.png" alt="" title="vsToastC3" width="600" height="449" class="alignnone size-large wp-image-2469" /></a></p>
<p>Now compile your plugin. You can do this inside ShiVa directly:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/openwin2.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/openwin2-600x379.png" alt="" title="openwin2" width="600" height="379" class="alignnone size-large wp-image-2500" /></a></p>
<h2>Java Plugin Programming in Eclipse</h2>
<p>Your workflow continues with Eclipse. Here we will create all the Java code used in our plugin, and export is as a self-contained .jar file.</p>
<p>Create a new Android project for your java classes.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/newandro.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/newandro-600x134.png" alt="" title="newandro" width="600" height="134" class="alignnone size-large wp-image-2480" /></a></p>
<p>Set your project as library. Right click on the Project > Properties > Android, and check &#8220;Is Library&#8221;. The project will now be generated as a .jar file instead of an .apk.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/islibrary.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/islibrary-600x391.png" alt="" title="islibrary" width="600" height="391" class="alignnone size-large wp-image-2461" /></a></p>
<p>In case you need to access the Activity or the View of the applicaion, add <code>S3DXAndroidTools.jar</code> to your project. This .jar file can be found in <code>Plugins\$yourplugin\Sources\S3DX</code>, alternatively in the UAT (Windows: <code>Data/Windows/Android/Build/S3DX</code>; Mac: <code>Contents/Resources/Data/Mac/Android/Build/S3DX</code>). Note that the file is only included in plugins created with ShiVa 1.9.2 beta4 or greater. </p>
<p>S3DXAndroidTools.jar has to be placed in the /libs folder of the Eclipse project and then added to the Project: Right click on the Project > Properties > Java Build Path > Libraries > Add JARs.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/javabuildpath.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/javabuildpath-600x512.png" alt="" title="javabuildpath" width="600" height="512" class="alignnone size-large wp-image-2462" /></a></p>
<p>Create a package for your classes and create your classes. Our example package is called com.stonetrip.toastlite and contains the file libToastLite.java.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/eclipseproject.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/eclipseproject-600x311.png" alt="" title="eclipseproject" width="600" height="311" class="alignnone size-large wp-image-2463" /></a></p>
<p>Create static methods in your class. Those methods will be called from the base plugin source files. In our example, we have created public static void ToastLite_Show (String sText).</p>
<pre style="padding-top:10px; padding-bottom:10px; background-color:#ccc;">package com.stonetrip.toastlite;

import android.app.Activity;
import android.widget.Toast;

import com.stonetrip.android.tools.*;

public class LibToastLite
{
    public static void ToastLite_Show (final String sText)
    {
        final Activity oThis = S3DXAndroidTools.getMainActivity();
        try {
        	oThis.runOnUiThread(new Runnable ( )
			{
			public void run ( )
				{
				Toast.makeText(oThis, sText, Toast.LENGTH_SHORT).show();
				}
			});
        	}
        catch ( Exception e ) { }
    }
}</pre>
<p>The .jar file is automatically generated in the /bin folder of your project. If the file is missing, that&#8217;s because you had build errors along the way.</p>
<p>Copy the .jar file to the ShiVa Plugin Android content folder. In our case, that would be <code>/Plugins/com.stonetrip.toastlite/Contents/Android</code>.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/jarcopywindows.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/jarcopywindows.png" alt="" title="jarcopywindows" width="437" height="108" class="alignnone size-full wp-image-2464" /></a></p>
<p>If your java class depends on other .jar files, copy those .jar files in the same place (Contents/Android). This will be the case if you are making plugins for a 3rd party SDK, like Flurry for instance (FlurryAgent.jar).</p>
<h2>ShiVa Export</h2>
<p>You can build your Android Plugin solution from within ShiVa. Double-click on your plugin, then go to the Settings gear in the Android line and select &#8220;Recompile&#8221; or &#8220;Compile&#8221;. This will generate the required <em>.a</em> library.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/compileandro1.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/compileandro1-600x162.png" alt="" title="compileandro" width="600" height="162" class="alignnone size-large wp-image-2492" /></a></p>
<p>If you are building on a Mac, execute the project makefile:</p>
<pre>cd "%PLUGIN_FOLDER%/Make/Android
make -f "ToastLite.makefile"</pre>
<p>If everything went well, both the Windows/C++ and the Android/a plugin should light up green:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/shivaplugcomplete.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2013/01/shivaplugcomplete-600x229.png" alt="" title="shivaplugcomplete" width="600" height="229" class="alignnone size-large wp-image-2456" /></a></p>
<p>All that is left for you to do now is the export from ShiVa. Do not forget to reference your new plugins in the Game Editor!</p>
<p>The exported STK will contain both .a and .jar files. Our Authoring Tool will compile them together, the user does not need to worry about adding native C++ or Java Files in the UAT.</p>
<p>Build your .apk using the ShiVa Authoring Tools v1.4.0.beta9 or greater.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2454-android-plugin-development-with-java-and-c/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The ShiVa Store &#8211; Public Beta</title>
		<link>http://www.shivaengine.com/developer/2016-the-shiva-store-public-beta</link>
		<comments>http://www.shivaengine.com/developer/2016-the-shiva-store-public-beta#comments</comments>
		<pubDate>Wed, 19 Dec 2012 09:48:39 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Store]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2016</guid>
		<description><![CDATA[You have waited a long time for the ShiVa Developer Store. Your voices have been heard. StoneTrip proudly announces the ShiVa Asset Store Public Beta! Become part of the ShiVa Seller family and start preparing your content today!]]></description>
			<content:encoded><![CDATA[<div style="width:600px;height:20px;">  </div>
<div><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/12/beta-blog-short.png" alt="storepic" title="storebeta" width="650" height="450" /></div>
<h2 style="margin-top: 45px;">Premium Content for a Premium Tool</h2>
<p>We are very happy to announce that the long-awaited ShiVa Store has just opened for public BETA testing. This means that everyone is invited to register at <a href="http://www.shivaengine.com/store/" target="_blank">http://www.shivaengine.com/store/</a>, browse the products available and buy content for your ShiVa projects. This BETA release features the first wave of StoneTrip-made plugins, fantastic 3D packages by Dexsoft Multimedia, the entire PanozK Sound Library as well as products made by several ShiVa Professionals from our community. More plugins and content from our premium partners will come in time. When we get out of the BETA stage, our customers will have a wide selection of professional and high quality content to choose from. No matter if you need a well designed and flawlessly animated model, a great material for your scene, a plugin for social network websites or a great ambient music track: There will be a package for everyone.</p>
<div style="float:right;"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/11/ste-150x150.png" alt="" title="ste" width="150" height="150" /></div>
<h2>Seamless Integration</h2>
<p>Content stores on the Internet usually sell their assets in a variety of formats. While this is not a big problem when you are dealing with textures or sounds, it can be a real hassle to convert models, especially if they are animated. With our store, these problem will be a thing of the past. The ShiVa Store is a STE store. That means, adding the content you just purchased to your ShiVa project is literally a matter of 5 clicks. No more conversion tools. No more frustration.</p>
<p>Still, we are open to new ideas and content that does not necessarily fit into an STE archive, that is why we have introduced a second product category into our store: Tools for ShiVa. Those EXE files are application that help ShiVa developers create, port or enhance their ShiVa-generated application and/or the creation workflow. If you have created such a Tool, you can sell it on our store as well.</p>
<h2>Prepare your Own Content</h2>
<p>Everyone is invited to the store. Everyone can use the content we host, even our customers who only work with the Free Web Edition of ShiVa. And if you have created something cool in ShiVa on your own, you can become a seller on the store yourself! All you need is a great product idea and the free Web Edition of ShiVa that you can download from our website, <a href="http://www.stonetrip.com/download.html">stonetrip.com/download</a>. That&#8217;s right, there are no setup fees, no signup fees for the store, no, you do not even need to pay for the tool that allows you to convert all your content into STE packages! The only limit is your imagination.</p>
<div style="float:right;"><img src="http://www.shivaengine.com/store/themes/leomarket/img/beta-sticker.png" alt="" title="beta" /></div>
<h2>Why Beta? Can I buy and sell packages today?</h2>
<p>We at StoneTrip are known for our expertise when it comes to cross-platform Engine Development and Tool Programming, but the collaborative e-market business is a new experience for us. We have taken great care and put a lot of time and effort into the store. Though we tried to think of everything, our large customer base is likely to discover some initial minor issues that will be fixed as soon as possible while the store is in beta.</p>
<p><a href="http://www.shivaengine.com/store">shivaengine.com/store</a> is fully functional. We invite everyone to create customer and seller accounts, package their assets and sell them on our marketplace. You will receive payments and everybody with a great product idea can participate. </p>
<p>We deeply trust in the current state of our store. For the launch lineup, we uploaded over a dozen great plugins made by ourselves, and more are to come soon.</p>
<h2>Becoming a Seller</h2>
<p>If you are a Content Creator yourself, you can create your own STK and EXE packages and upload them to the store. Everything you need to know to do that is described on our official Store Documentation Page<br />
<a href="http://www.stonetrip.com/developer/doc/store/introduction" target="_blank">The ShiVa Asset Store &#8211; Introduction @ShiVaEngine.com Docs</a></p>
<div style="padding:10px; float:left; margin-right:15px; margin-bottom:5px; margin-top:-5px;"><img src="http://www.stonetrip.com/developer/doc/html/store/images_introduction/Profile.png" alt="" /></div>
<p>To become a seller, you have to create a Customer Account first: <a href="http://www.stonetrip.com/developer/doc/store/useraccount" target="_blank">User Account @ShiVaEngine.com Docs</a><br />
Then, apply for a seller account and wait until your account has been approved. This is done by hand, so please excuse a little waiting time. <a href="http://www.stonetrip.com/developer/doc/store/selleraccount" target="_blank">Seller Account @ShiVaEngine.com Docs</a></p>
<h2>Preparing your Assets</h2>
<p>To ensure the quality and accessibility of the store and its contents, we have assembled a number of 3d asset, packaging and binary guidelines.</p>
<div style="padding:10px; float:left; margin-right:25px; margin-bottom:5px; margin-top:-5px;"><img src="http://www.stonetrip.com/developer/doc/html/store/images_introduction/Package.png" alt="" /></div>
<ul>
<li><a href="http://www.stonetrip.com/developer/doc/store/packageguidelines" target="_blank">Packaging Guidelines @ShiVaEngine.com Docs</a></li>
<li><a href="http://www.stonetrip.com/developer/doc/store/assetguidelines" target="_blank">Asset Guidelines @ShiVaEngine.com Docs</a></li>
<li><a href="http://www.stonetrip.com/developer/doc/store/exetools" target="_blank">EXE Tool Guidelines @ShiVaEngine.com Docs</a></li>
</ul>
<h2>Everything Legal</h2>
<p>To make the ShiVa store a pleasant experience for everyone, binding legal documents are a necessity not only for us, but every user and seller.</p>
<p>Terms of Service: <a href="http://www.shivaengine.com/store/cms.php?id_cms=8">Read the Terms on our Store Website</a><br />
Provider Agreement: <a href="http://www.shivaengine.com/store/cms.php?id_cms=9">Read the Provider Agreement on our Store Website</a><br />
Appendix 1: <a href="http://www.shivaengine.com/store/cms.php?id_cms=10">Read the Appendix 1 on our Store Website</a></p>
<p>Do you want to be a part of the ShiVa seller family? Prepare your content today and be one of the first to offer your STEs!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2016-the-shiva-store-public-beta/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Caching and External Sources</title>
		<link>http://www.shivaengine.com/developer/2367-caching-and-external-sources</link>
		<comments>http://www.shivaengine.com/developer/2367-caching-and-external-sources#comments</comments>
		<pubDate>Tue, 20 Nov 2012 08:24:35 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2367</guid>
		<description><![CDATA[Learn how to use the cache and system APIs to stream remote videos, textures, and game content to your ShiVa application!]]></description>
			<content:encoded><![CDATA[<h2>Remote Environments and XML</h2>
<p>In the past, we have written a lot about Remote XML manipulation and Distant Environments. Using those APIs, you can easily load save games, highscores and configuration data. Here is a short list to refresh your memory:</p>
<ul>
<li><a href="http://www.shivaengine.com/developer/343-environment-management" target="_blank">Environment Management</a></li>
<li><a href="http://www.shivaengine.com/developer/377-xml-manipulation" target="_blank">XML Manipulation</a></li>
<li><a href="http://www.shivaengine.com/developer/1656-get-an-xml-without-using-states" target="_blank">XML without States</a></li>
<li><a href="http://www.shivaengine.com/developer/2061-shiva-flash-xml-highscore-example" target="_blank">XML Highscore</a></li>
</ul>
<p>However, those APIs are limited in a way that you can only load string data, not objects, videos, materials, scripts and so on. This tutorial will show you how to load, cache and use distant resources.</p>
<h2>Streaming Web Videos</h2>
<p>You can stream videos directly from the internet and show them to your users. Although the name would certainly suggest so, <em>application.playOverlayExternalMovie ( )</em> &#8211; a function used primarily to load films that have been added to the &#8220;Additional Files&#8221; column in the UAT &#8211; is not the correct way to do that. Use the <em>cache</em> API instead.</p>
<p>Building a Big Buck Bunny Web Video Player in ShiVa is really easy:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">--note the extension(s)</span>
cache.addFile <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;BigBuckBunnyVideo.ogg&quot;</span>, <span style="color: #888800;">&quot;http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv&quot;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Streaming videos must be a Theora Video / Vorbis Audio stream, commonly packaged in an *.ogg or *.ogv container.</p>
<p>You now have to decide whether you want to play the film on a HUD element or on a material texture.</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">--HUD code, note that extensions are absent</span>
<span style="color: #0000ff;">hud</span>.setMovieClip <span style="color: #66cc66;">&#40;</span> hToYourMovieComponent, <span style="color: #888800;">&quot;BigBuckBunnyVideo&quot;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The movie will start to play immediately after that if you do not pause the stream explicitly. You can either control the Video using HUD actions&#8230;</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/11/hudaction.png"><img class="alignnone size-full wp-image-2370" title="hudaction" src="http://www.shivaengine.com/developer/wp-content/uploads/2012/11/hudaction.png" alt="" width="368" height="392" /></a></p>
<p>&#8230; or do it completely in code:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #0000ff;">local</span> hUser <span style="color: #66cc66;">=</span> <span style="color: #0000ff;">this</span>.getUser <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #0000ff;">local</span> hPlayStreamMovie <span style="color: #66cc66;">=</span> <span style="color: #0000ff;">hud</span>.newAction <span style="color: #66cc66;">&#40;</span> hUser, <span style="color: #888800;">&quot;PlayStreamMovie&quot;</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">hud</span>.beginActionCommand <span style="color: #66cc66;">&#40;</span> hPlayStreamMovie, <span style="color: #0000ff;">hud</span>.kCommandTypePlayMovie <span style="color: #66cc66;">&#41;</span>
<span style="color: #008000; font-style: italic;">--assuming your Movie Player HUD is named &quot;MoviePlayer&quot; and your movie component &quot;Movie&quot;</span>
<span style="color: #0000ff;">hud</span>.pushActionCommandArgument <span style="color: #66cc66;">&#40;</span> hPlayStreamMovie, <span style="color: #0000ff;">hud</span>.getComponent <span style="color: #66cc66;">&#40;</span> hUser, <span style="color: #888800;">&quot;MoviePlayer.Movie&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">hud</span>.endActionCommand <span style="color: #66cc66;">&#40;</span> hPlayStreamMovie <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #0000ff;">hud</span>.callAction <span style="color: #66cc66;">&#40;</span> hUser, <span style="color: #888800;">&quot;PlayStreamMovie&quot;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>You should also remove the video from cache when the program finishes, using the <em>onApplicationWillQuit (  )</em> handler:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">--delete downloaded movie from cache</span>
cache.removeFile <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;BigBuckBunnyVideo.ogg&quot;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Movie Playback on a material texture looks similar:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">--load...</span>
shape.overrideMeshSubsetMaterialEffectMap0  <span style="color: #66cc66;">&#40;</span> hYourObject, nMaterialSubsetIndex, <span style="color: #888800;">&quot;BigBuckBunnyVideo&quot;</span>, shape.kMapTypeMovie <span style="color: #66cc66;">&#41;</span>
<span style="color: #008000; font-style: italic;">-- ...and playback</span>
shape.playMeshSubsetMaterialEffectMap0Movie <span style="color: #66cc66;">&#40;</span> hYourObject, nMaterialSubsetIndex <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>For a working example, please check out the MoviePlayer Sample that comes with every ShiVa installation.</p>
<p>It is also possible to stream videos directly without saving them to your disk. Instead of <em>cache.addFile</em>, simply use <em>cache.addStreamFile</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">--stream it!</span>
cache.addStreamFile <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;BigBuckBunnyVideo.ogg&quot;</span>, <span style="color: #888800;">&quot;http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv&quot;</span> <span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The playback code remains the same, but you do not need to <em>cache.removeFile</em> the movie after you are done with it.</p>
<p>Note to all Web Player games creators: The Chrome browser will try to read incoming .ogg files on its own and the download of the video will stop. To avoid this, you just have to rename the remote .ogg stream to something else, like .dat, .blu, whatever you want.</p>
<h2>Loading Texture Files</h2>
<p>Do you want your gamer community to be able to use custom skins? Do you have a billboard in your scene you want to display ads on, and change those images over time? Thankfully, you do not have to replace the whole STK to make those changes. Textures can be loaded directly from the Internet, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #0000ff;">if</span> <span style="color: #66cc66;">&#40;</span> cache.getFileStatus  <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;pictureWeb.tga&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span>
    cache.addFile <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;pictureWeb.tga&quot;</span>, <span style="color: #888800;">&quot;http://www.stonetrip.com/developer/dump/picture.tga&quot;</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">end</span></pre></div></div>

<p>This works well for JPG and TGA images. DDS produces mixed results and anything else like PNG or BMP will throw you a &#8220;resource not referenced&#8221; error message. DDS, PVR, ETC are supported on GPUs that can handle those compressed file formats. To stay truly cross-platform, we recommend going with JPG and TGA.</p>
<p>You can now display those textures on your objects. This is very similar to the way we used the ogg video.</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">--note: no extension again</span>
<span style="color: #0000ff;">if</span> <span style="color: #66cc66;">&#40;</span> cache.getFileStatus  <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;pictureWeb.tga&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span>
    shape.overrideMeshSubsetMaterialEffectMap0  <span style="color: #66cc66;">&#40;</span> hYourObject, nMaterialSubsetIndex, <span style="color: #888800;">&quot;pictureWeb&quot;</span>, shape.kMapTypeTexture <span style="color: #66cc66;">&#41;</span>
    <span style="color: #008000; font-style: italic;">--now leave this loop/state either by entering another state...</span>
    <span style="color: #008000; font-style: italic;">--this.null()</span>
    <span style="color: #008000; font-style: italic;">--...or by setting a control variable:</span>
    <span style="color: #008000; font-style: italic;">--this.bTexturesPreloaded(true)</span>
<span style="color: #0000ff;">end</span></pre></div></div>

<p>Make sure that the whole file is loaded (query <em>cache.getFileStatus</em> until it equals 1) before you use the new image, otherwise you will not see any changes in your scene and the function will silently fail.</p>
<p>This function should run in a loop, preferably in its own state. As soon as the texture is cached, <em>cache.getFileStatus</em> will always return 1, so make sure you exit the loop after the &#8220;== 1&#8243; branch has run exactly once. If you use states, switch to another state, and if you do everything in onEnterFrame, use a member control variable and encapsulate the whole preloading code into one if-branch <em>this.bTexturesPreloaded() == false</em>.</p>
<h2>Caching and running remote Game STKs</h2>
<p>TheHunt sample game that comes with ShiVa is split into 2 games. One is called st_loading and contains the airplane scene as well as the caching code for the hunt game STK which lies remotely on the StoneTrip servers, the other one is theHunt STK itself. Essentially, running theHunt on the web, you are executing a game within a game.</p>
<p>Interestingly, you do not need to use the cache.add API to load remote game STKs. Loading and executing is done with the <em>system</em> API, <em>system.install</em> in particular.</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #0000ff;">local</span> sFileToLoadURI <span style="color: #66cc66;">=</span> <span style="color: #888800;">&quot;http://.....&quot;</span>
<span style="color: #0000ff;">local</span> nProgress <span style="color: #66cc66;">=</span> system.getInstallationStatus <span style="color: #66cc66;">&#40;</span> sFileToLoadURI <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">if</span> <span style="color: #66cc66;">&#40;</span> nProgress <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">then</span>
       system.install <span style="color: #66cc66;">&#40;</span> sFileToLoadURI <span style="color: #66cc66;">&#41;</span>
<span style="color: #008000; font-style: italic;">-- [...]</span></pre></div></div>

<p>Still, it can be beneficial to download (cache) the file first, save it to disk, and then run it. We will approach this issue in the last chapter of this tutorial, &#8220;Saving Cached Resources&#8221;.</p>
<p>If you rely on <em>system.install</em>, you can query the current download progress can using <em>system.getInstallationStatus</em>. As soon as it returns 1, the pack is ready. Finally, launch the new game from the STK using <em>system.launch</em>. Note how the pack string is a generic variable that could either be a local or a remote resource.</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">-- [...]</span>
<span style="color: #0000ff;">elseif</span> <span style="color: #66cc66;">&#40;</span> nProgress <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">then</span>
      system.launch <span style="color: #66cc66;">&#40;</span> sFileToLoadURI, <span style="color: #888800;">&quot;&quot;</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">end</span></pre></div></div>

<p>You should note that the Install System is not available when running your game inside the editor, which makes it impossible to test it without a proper export first.</p>
<p>For more a more in-depth code example, you should go through the <em>st_loading</em> sample inside ShiVa as well as look at the <a href="http://www.stonetrip.com/developer/doc/api/system#Installation" target="_blank">corresponding doc pages</a>. Some time ago, we have also written a <a href="http://www.shivaengine.com/developer/1032-launch-a-game-from-another-game" target="_blank">specific tutorial about launching STK games from within games</a>.</p>
<h2>Loading remote Resource STKs</h2>
<p>Not all resources can be loaded as separate files. While it is possible to load single images, models for instance cannot be loaded as individual files. To load resources other than textures, movies, XML end environment data, you have to pack them int STK archives and cache them into shiva.</p>
<p>Resource STKs should not contain games. Create them by right-clicking on your desired item and choose &#8220;Add to Export&#8221;. After you have added everything you want to group into one pack, click &#8220;Export&#8221; in that window and choose &#8220;STK&#8221; as export option.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/11/export.png"><img class="alignnone size-large wp-image-2392" title="export" src="http://www.shivaengine.com/developer/wp-content/uploads/2012/11/export-600x408.png" alt="" width="600" height="408" /></a></p>
<p>Caching resource STKs is similar to caching textures or videos. For simplicity reasons, I have unloaded the caching function into its own userAI state:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">--------------------------------------------------------------------------------</span>
<span style="color: #0000ff;">function</span> Main.loadResources_onLoop <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #008000; font-style: italic;">--------------------------------------------------------------------------------</span>
&nbsp;
    <span style="color: #0000ff;">local</span> nProgress <span style="color: #66cc66;">=</span> cache.getFileStatus  <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;ResourcePack.stk&quot;</span> <span style="color: #66cc66;">&#41;</span>
    <span style="color: #0000ff;">log</span>.message <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;STK loading onLoop progress: &quot;</span>..nProgress <span style="color: #66cc66;">&#41;</span>
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #66cc66;">&#40;</span> nProgress <span style="color: #66cc66;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span>
        cache.addFile <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;ResourcePack.stk&quot;</span>, <span style="color: #888800;">&quot;http://www.stonetrip.com/developer/dump/ResourcePack.stk&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #008000; font-style: italic;">--remote file</span>
        <span style="color: #008000; font-style: italic;">-- or if you want, a local file:</span>
        <span style="color: #008000; font-style: italic;">--cache.addFile ( &quot;ResourcePack.stk&quot;, &quot;file://C:/path/to/your/ResourcePack.stk&quot; )</span>
    <span style="color: #0000ff;">end</span>
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #66cc66;">&#40;</span>nProgress <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span>
        <span style="color: #008000; font-style: italic;">--load a HUD that was in the resource pack</span>
        <span style="color: #0000ff;">hud</span>.newTemplateInstance <span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">this</span>.getUser <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>, <span style="color: #888800;">&quot;ResourcePack/iPhoneJoypadEmulation&quot;</span>, <span style="color: #888800;">&quot;JoyPad&quot;</span> <span style="color: #66cc66;">&#41;</span>
        <span style="color: #0000ff;">this</span>.null <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #008000; font-style: italic;">-- go to another state and leave the loop</span>
    <span style="color: #0000ff;">end</span>
&nbsp;
<span style="color: #008000; font-style: italic;">--------------------------------------------------------------------------------</span>
<span style="color: #0000ff;">end</span>
<span style="color: #008000; font-style: italic;">--------------------------------------------------------------------------------</span></pre></div></div>

<p>Every resource in the pack can now be accessed through its <em>PackName/ResourceName</em> handle.</p>
<h2>Saving Cached Resources</h2>
<p>External STKs can grow fairly big. Though an option exists not to clear the cache every time the engine stops (see image below), it is more elegant to save your cached files to your local storage device.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/11/cachesetting.png"><img class="alignnone size-large wp-image-2380" title="cachesetting" src="http://www.shivaengine.com/developer/wp-content/uploads/2012/11/cachesetting-600x652.png" alt="" width="600" height="652" /></a></p>
<p>You can permanently save a cached file to disk using <em>cache.sendFile</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #0000ff;">if</span> <span style="color: #66cc66;">&#40;</span> cache.getFileStatus  <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;package.stk&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">then</span>
    cache.sendFile <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;package.stk&quot;</span>, <span style="color: #888800;">&quot;file://&quot;</span>..application.getPackDirectory <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>..<span style="color: #888800;">&quot;/package.stk&quot;</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">end</span></pre></div></div>

<p>Check for the local STK first before downloading a new one.</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #0000ff;">local</span> tFiletable <span style="color: #66cc66;">=</span> <span style="color: #0000ff;">table</span>.newInstance <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>
system.findFiles <span style="color: #66cc66;">&#40;</span> tFiletable, <span style="color: #888800;">&quot;file://&quot;</span>..application.getPackDirectory <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>..<span style="color: #888800;">&quot;/&quot;</span>, <span style="color: #888800;">&quot;*.stk&quot;</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #008000; font-style: italic;">--or wherever you decided to save your cached STKs</span>
&nbsp;
<span style="color: #0000ff;">if</span> <span style="color: #0000ff;">table</span>.contains <span style="color: #66cc66;">&#40;</span> tFiletable, <span style="color: #888800;">&quot;package.stk&quot;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">then</span>
    <span style="color: #0000ff;">this</span>.sFileToLoadURI <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;file://&quot;</span>..application.getPackDirectory <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#41;</span>..<span style="color: #888800;">&quot;/package.stk&quot;</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">else</span>
    <span style="color: #0000ff;">this</span>.sFileToLoadURI <span style="color: #66cc66;">&#40;</span> <span style="color: #888800;">&quot;http://www.stonetrip.com/content/techdemo/package.stk&quot;</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #0000ff;">end</span></pre></div></div>

<p>The rest of the caching code stays the same, the only difference being the fact that you cache from a local disk rather than a remote host. this method works with both system.install ( local or remote URI ) and cache.add ( local or remote URI ).</p>
<p>However, you should check if there is a newer version of the STK on the internet. <em>cache.getFileStatus</em> offers this functionality. When you use cache.getFileStatus and set application.setOption ( application.kOptionNetworkStreams, x ) with x &gt; 0 (default x == 1), the engine has to check on the server if a newer version of the file is available. For complete documentation on that topic, please read up on it <a href="http://www.stonetrip.com/developer/doc/api/cache-getFileStatus" target="_blank">on the corresponding doc pages</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2367-caching-and-external-sources/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://clips.vorwaerts-gmbh.de/big_buck_bunny.ogv" length="4654162" type="video/ogg" />
		</item>
		<item>
		<title>The ShiVa 2012-13 Roadmap</title>
		<link>http://www.shivaengine.com/developer/2290-the-shiva-2012-13-roadmap</link>
		<comments>http://www.shivaengine.com/developer/2290-the-shiva-2012-13-roadmap#comments</comments>
		<pubDate>Thu, 04 Oct 2012 08:19:17 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2290</guid>
		<description><![CDATA[For months now if not years, a part of our team is working exclusively on the upcoming ShiVa 2.0 Editor. Get your latest Stonetrip ShiVa development updates here!]]></description>
			<content:encoded><![CDATA[<h2>Dear Customers, Colleagues, Friends and ShiVa-istas,</h2>
<p>the ShiVa 1.X editor has grown and expanded years after years up to the point where it became hard to maintain and evolve. For months now if not years, a part of our team is working exclusively on the upcoming ShiVa 2.0 Editor. For ShiVa 2.0, we decided to rewrite everything from scratch, to give you all the latest features you have been so eagerly demanding, like a more flexible user interface, full LUA 5.1 support, multicore-support in the editor, customizable shaders, and so much more.</p>
<p>Rewriting everything was not only a big challenge, it might have been a little crazy, too. But looking back, it turned out to be the right decision. Most of the hard work is now behind us. But indeed, that also means the 2.0 editor is not yet finished. We know we are late and we have failed to meet our own Spring 2012 deadline. But we are convinced that our paying customers expect the best product they can imagine, and we do not want to release something unfinished. We truly believe it will be worth the wait.</p>
<h2>A New Star on the Horizon: ShiVa 2.0</h2>
<p>We wanted to let you know we are actually, really, definitively and hard working on this release. And for the first time in years, we have decided to give you a peek at the new XML- and LUA-driven interface. So, without further ado, here are two screenshots of ShiVa 2.0 (64 bit) running natively on Mac OS X:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/ShiVa_Editor_Mac.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/ShiVa_Editor_Mac-600x375.png" alt="" title="ShiVa_Editor_Mac" width="600" height="375" class="aligncenter size-large wp-image-2296" /></a></p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Actually_On_Mac.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Actually_On_Mac-600x375.png" alt="" title="Actually_On_Mac" width="600" height="375" class="aligncenter size-large wp-image-2291" /></a></p>
<p>So, when can you get your hands on it? Unfortunately, we are not close to a release date yet. We know we are quite behind on our release schedule, but we simply do not have the same manpower than some other game IDE providers. Also, we give high priority to our paid support customers, which slows down our core development considerably. But do not fear, ShiVa 2.0 will eventually see the light &#8211; you know the old developer saying &#8211; when it&#8217;s done.</p>
<h2>Expanding the Portfolio</h2>
<p>ShiVa is and has ever been the most cross-platform game engine in the world. This is something we have always believed in, and we have designed ShiVa 2.0 with that in mind. We are constantly working on new engine ports. In the near future, you can look forward to</p>
<ul>
<li>Direct X 11, Windows 8 Metro and</li>
<li>Sony PS Vita Engines.</li>
</ul>
<p>ShiVa-powered games that are created today will run on Windows 8 flawlessly. But as soon as you consider putting a game on the Windows Store, this is a completely different story. Pushing the engine to DX11 means brain surgery, a major part of the engine needs to be updated. Among other things, we needed to implement a full Direct X 11 rendering backend and find a viable strategy for dynamically generated shaders, two rather slow and everything but straightforward tasks, believe us!</p>
<p>The ShiVa engine will be available for the Sony PS Vita next year. Amazingly enough, more than 5 ShiVa-powered games are already planned on that platform, and many more are expected!</p>
<h2>Keeping you up to date: ShiVa 1.9.2 and UAT 1.4</h2>
<p>We decided to release a new ShiVa 1.9.x version, along with the ShiVa Authoring Tool 1.4, to bridge the gap until ShiVa 2.0 hits the market. This free update will bring some ShiVa 2.0 engine features, including:</p>
<ul>
<li>new post rendering filters, such as SSAO or 3D LUT based Color Grading</li>
<li>new particles options such as Attractors, Texture Sheets or Velocity Scale</li>
<li>new scripting functions such as vertex colors control and runtime lights baking, and</li>
<li>new supported texture pixel formats, such as RGBA4444 or RGB565.</li>
</ul>
<p>Here are some screenshots of the upcoming SSAO post rendering filter:</p>
<table>
<tr>
<td><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/SSAO_1_OFF.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/SSAO_1_OFF-300x189.png" alt="" title="SSAO_1_OFF" width="300" height="189" /></a></td>
<td><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/SSAO_1_ON.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/SSAO_1_ON-300x189.png" alt="" title="SSAO_1_ON" width="300" height="189" /></a></td>
</tr>
<tr>
<td><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/SSAO_2_OFF.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/SSAO_2_OFF-300x189.png" alt="" title="SSAO_2_OFF" width="300" height="189" /></a></td>
<td><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/SSAO_2_ON.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/SSAO_2_ON-300x189.png" alt="" title="SSAO_2_ON" width="300" height="189" /></a></td>
</tr>
</table>
<p>While this release does not focus on the user interface and tools, it will nevertheless include: </p>
<ul>
<li>import improvements and additional options</li>
<li>integrated SVN improvements</li>
<li>skinned meshes optimization tools and</li>
<li>various workflow improvements.</li>
</ul>
<p>The UAT 1.4 will also bring the Windows Phone 7 engine, including a specific audio format export process, so users will finally be able to export for that platform using all supported features.</p>
<p>Some pictures of the upcoming 3D LUT-based Color Grading post rendering filter:</p>
<table>
<tr>
<td><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Dragon_CG_1.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Dragon_CG_1-300x189.png" alt="" title="Dragon_CG_1" width="300" height="189" /></a></td>
<td><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Dragon_CG_2.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Dragon_CG_2-300x189.png" alt="" title="Dragon_CG_2" width="300" height="189" /></a></td>
</tr>
<tr>
<td><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Dragon_CG_3.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Dragon_CG_3-300x189.png" alt="" title="Dragon_CG_3" width="300" height="189" /></a></td>
<td><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Dragon_CG_4.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/10/Dragon_CG_4-300x189.png" alt="" title="Dragon_CG_4" width="300" height="189" /></a></td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2290-the-shiva-2012-13-roadmap/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Study: SplashFox Games</title>
		<link>http://www.shivaengine.com/developer/2260-case-study-splashfox-games</link>
		<comments>http://www.shivaengine.com/developer/2260-case-study-splashfox-games#comments</comments>
		<pubDate>Fri, 14 Sep 2012 08:35:12 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2260</guid>
		<description><![CDATA[The young Ukrainian game developer Vyacheslav Klymenko, programmer of some of the most successful 2D games made with ShiVa 3D, shares his thoughts on 2D game creation, the freemium business model and rapid game development with us.]]></description>
			<content:encoded><![CDATA[<p><b>Hello Vyacheslav! Most users know you as vklymenko on the forum and/or have played one of your numerous 2D games you created with ShiVa. Your apps showcase an attention to detail that is fairly uncommon in the hobbyist scene, you obviously have been doing game development long before ShiVa3D. When did you start and how did you end up with StoneTrip’s engine?</b></p>
<p>Good day! First of all I wanted to say thank you to StoneTrip for the chance to be here, it is a big pleasure for me.</p>
<p>I had a crazy chance to get my first PC when I was only 8 years old, and I made my first game when I was 10. I started with early versions of Delphi and switched to Dark Basic later on, but I cannot say that I really was a programmer back then.</p>
<p>I do not want to make black and white advertisement for competitive middleware tools, but I really had a hard time with some other game engines. Among the most annoying problems were “memory leaks”: I was working with “this” engine for years, mostly PC games, when I switched to mobile platforms exclusively and problems kept creeping up on me. I spent crazy amounts of time trying to fix those leaks, but the games crashed constantly while the official site went silent &#8211; I did not know what to do and clients were expecting results. So I started to look into other game engines, and one day, I found ShiVa3D. At first, the interface was a little confusing to me, having avoided visual editors for most of my life. I was used to working with text editors and folders with scripts. But just a week later and&#8230; hey! I got the hang of it. The editor is done in a very professional way, so organized and easy to use. On the second week, I started porting my previous games, and by the end of the month, I had ported all my freelance games, got milestone payments, released the games and was happy as hell. No any single issue, no annoying memory leaks &#8211; everything just worked as it should. Development is pretty easy, especially for small 2D games. Currently I am porting some flash games, like 1 per week &#8211; yes, development with ShiVa can be that fast! Principal programming on Combo Poker for instance was finished in less than a day.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/09/CrazyAnimals.png" style="display: inline-block; float:left; margin:20px;margin-left:0px;margin-top:0px;"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/09/CrazyAnimals-300x225.png" alt="" title="CrazyAnimals" width="300" height="225" class="aligncenter size-medium wp-image-2265" /></a>ShiVa has truly changed my life. A 3D GameDev tool is not some product like an email client that you just need to have, but don&#8217;t really care which one exactly. Without ShiVa, I could never have created so many freelance projects and built my own passive income.</p>
<p>Another thing I am impressed with is the community. I believe most people on the forum are really great at what they do and are working on “big” things. That is probably why they are so friendly. Some time ago, I was running in circles to integrate Game Center into my mobile game for a client, so I was in a big hurry to get things done in less than a day. I thought I would not be able to get it working in time because it required ObjC, xCode and knowledge of the iPhone SDK. I posted a request on the board, then a guy &#8211; Dave &#8211; wrote a working sample for me! This is just one of many examples. As a Thank You, I am trying to give back to the community and help other game developers, posting all my key solutions and implementations.</p>
<p><b>You are one of the most active 2D ShiVa game developers we know, although ShiVa is primarily a cross-platform 3D engine and was not exactly designed with easy 2D tools in mind. What made you choose ShiVa nevertheless, which features stand out to you?</b></p>
<p>On the contrary, I think it&#8217;s great for 2D! I made a real time 2D strategy game, 2D side-scrollers, card games, some games with multiplayer support, some physics based apps. Apart from the games we released, if you take into account all the prototypes i have lying around on my hard drive, we have made close to 100 2D games with ShiVa.</p>
<p>I will not point out again how many platforms ShiVa supports – we all know that. When I am ready to publish a game, I am just exporting it with the Unified Authoring Tool for my intended targets and it takes less then a day for me to release for iOS, Android and Amazon. Most of my time is spent uploading screenshots and fill all the forms on the accounts, not actually coding the ports.</p>
<p>The ShiVa engine itself does not add much to your game file size, most of the small games I have been making are between 12 and 15 Mb. As most stores impose a restriction on app sizes, that’s a good thing too.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/09/Necronomicon2.jpg"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/09/Necronomicon2-600x356.jpg" alt="" title="Necronomicon2" width="600" height="356" /></a></p>
<p><b>What were some of the biggest obstacles you had to overcome when designing 2D games with ShiVa? Any tips for aspiring game designers?</b></p>
<p>The only problem with 2D games is collision detection. Of course it is possible to use 3D objects and create 2.5D or “fake 2D” scenes &#8211; like a lot of people are doing &#8211; but I am using HUDs 90% of the time. It would be really handy to have such an auto-collision detection feature for HUDs, as well as automatic texture atlas creation.</p>
<p>As far as tips for aspiring game developers go, here are some general rules that helped me along the way:</p>
<ul>
<li>Work fast, do not start 10 games without finishing any of them. If you feel that one game is going nowhere, kill its development, but find the reasons why it did not work. You can only make something great if you like the process of creating it.</li>
<li>Use social network sharing on Facebook and Twitter. They are not hard to implement and help to promote your game a lot.</li>
<li>No app is safe, and cracks are everywhere &#8211; do not count only on paid downloads. More and more developers are going “freemium”. In-app purchases + ads are a viable business model.</li>
<li>Banners will make you money for sure. Integrate RevMob and Chartboost. You can easily earn $100-200 per day with ads alone, and while revenue will slow down after a while, you will get a constant $10-20 per day &#8211; that is $300-600 per month. Per game.</li>
<li>Thanks to ShiVa, you can release on a lot of platforms, do not miss out on that. </li>
<li>Keep releasing updates for your games, even if the update is minor, to increase download numbers.</li>
<li>Include a “more games” button in your game. Promote your own games!</li>
</ul>
<p><iframe width="640" height="480" src="http://www.youtube.com/embed/MTfuJvPB-b4" frameborder="0" allowfullscreen></iframe></p>
<p><b>Can you share any tips on how to approach a 2D game? Is the workflow significantly different from making a 3D game?</b></p>
<p>I believe there is no big difference between using HUDs or 3D quad objects. It depends on the game you want to make. Use 3D quad objects if you want to make the next Angry Birds, but if you prefer puzzle, classic arcade or strategy games, use HUDs. Animations are a bit tricky either way. Use scripted actions. You can combine “sleep” commands with UV offset/scale to produce frames playing with milliseconds of delay between them. Switching textures for animations is essentially the same for HUDs, you just don&#8217;t need to create materials before using them.</p>
<p>I keep my artwork at high resolutions during development until the whole game is ready, and then just downsize it to different resolutions, depending on the target device. All my resources are named accordingly, like “_2048” or “_512” (e.g. “MainMenu_2048”). A variable in code handles which art pack to load, so all my games are universal and run on all iOS or Android mobile devices without any adjustments. You will find this trick in all of my HUD initializations: “hud.setComponentBackgroundImage ( h, “MainMenuAtlas_”..this.sDevice())</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/09/Zombilution.png" style="display: inline-block; float:left; margin:20px;margin-left:0px;margin-top:0px;"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/09/Zombilution-300x300.png" alt="" title="Zombilution" width="300" height="300" class="alignleft size-medium wp-image-2270" /></a></p>
<p><b>Mobile devices are becoming more and more powerful, the hardware is advancing rapidly. In a world of 3D movies and television where everybody talks about VR, how long do you think there will be a place for 2D games?</b></p>
<p>Good question. It is possible that the majority of future games will be VR based, but i doubt that this will happen within the next 5 years. Currently, mobile devices are still fairly weak when it comes to 3D games, and in terms of sales, 2D games clearly win on mobiles. It is pretty hard to make a good 3D game in general, now take into account the small screen and the low performance &#8211; in fact, if you are planning your first game, don’t make it 3D. It will do so-so on the mobile marketplace and you will probably not get anything out of this but disappointment. Only go 3D if you know what you are doing and have a lot of experience.</p>
<p><b>To be honest, i have lost count of how many games you have created and successfully published to the App Stores of the world &#8211; how many are there exactly, and what can we look forward to in the next coming months?</b></p>
<p>I have lost count too. But since you asked me &#8211; I would say about 100 games and prototypes. A while ago I was working for local network companies, I have signed NDAs with all of them so can not comment on everything that is in the works, but I had a chance to work for such big companies like Philip Morris.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/09/CrazyAnimalsOffice.jpg" style="display: inline-block; float:right; margin:20px;margin-right:0px;margin-top:0px;"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/09/CrazyAnimalsOffice-300x225.jpg" alt="" title="CrazyAnimalsOffice" width="300" height="225" class="aligncenter size-medium wp-image-2266" /></a>Probably one of most successful games I made is Necronomicon (Necronomicon Redux is latest HD version) – a cards game based on H. P. Lovecraft&#8217;s works, which saw thousands of paid downloads per day. Another interesting game was Zombilution, a top-down 2D action shooter. When I switched the game from paid to free, I got 100,000 downloads in a day or two, mostly from China. Crazy Animals is probably the most polished game I have done in terms of gameplay and UI. In the picture you can see the room where the game was tested &#8211; we take testing very seriously! I can safely say that Crazy Animals is one of most fun and addictive games on the AppStore I have ever played.</p>
<p>As for upcoming projects, we have County Fair, a tycoon game like “Build-a-lot”, we also work on 2 side-scroller adventure games. And then there is my personal favourite, “Versus Vitality” &#8211; a 2D RTS inspired by StarCraft, WarCraft and Dune2000. You know how hard it is to make such a game&#8230; I am trying to make the best strategy game for mobile devices with great graphics and gameplay. I am mostly handling the coding, but our SplashFoxGames team spent a lot of effort on everything else. Nevertheless, it soon became clear that we could not achieve our ambitious goals without external help and financing. We are currently trying to move Versus Vitality to Kickstarter.com, inspired by the recent indie game crowd funding success stories.</p>
<p><iframe width="640" height="480" src="http://www.youtube.com/embed/Qz3WISzWbGo" frameborder="0" allowfullscreen></iframe></p>
<p><b>Thank you very much for the interview! We wish you all the best with your latest games as well as your future endeavors!</b></p>
<hr />
<p><b>About Splashfox Games</b></p>
<p>The Ukraine-based game developer Splash Fox Games consists of game logic programmer Vyacheslav Klymenko, co-programmer Anatoliy Motornyi, game designer Konstantin Malinovskyi (owner of Witeg Art Studio), Ben Satterwhite (owner of SharkWeed) and Lawrence Steele from Satsuma Audio.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2260-case-study-splashfox-games/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Elegant Level Changing</title>
		<link>http://www.shivaengine.com/developer/2217-elegant-level-changing</link>
		<comments>http://www.shivaengine.com/developer/2217-elegant-level-changing#comments</comments>
		<pubDate>Tue, 21 Aug 2012 07:40:32 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Basics]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2217</guid>
		<description><![CDATA[Changing a level scene is just one line away with application.setCurrentUserScene. But can you do it the elegant way?]]></description>
			<content:encoded><![CDATA[<h2>setCurrentUserScene</h2>
<p><em>application.setCurrentUserScene ( hScene )</em> is among the first commands you get to know while learning ShiVa. Called from a User AI, it loads a game scene for the gamer to play in. It is also the most important command when trying to change a level.</p>
<p>Most games allow the player to walk through doors or into a certain area to change the level. The goal of this tutorial will be to recreate such a scene and show how to make an elegant level change including features like music and screen fading.</p>
<h2>Sensor Setup</h2>
<p>In order to capture the collision event between the main player character and the level exit, we have to assign sensors to all the objects involved, the player model as well as the exit blocks.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl1.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl1-600x261.png" alt="" title="lvl1" width="600" height="261" class="aligncenter size-large wp-image-2218" /></a></p>
<p>The Level Change Sensor has an ID of 99 to differentiate it from from other sensor collision events. Furthermore, the sensor boxes have name tags that indicate which level is next.</p>
<p>The collision event is captured on the player AI model:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl2.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl2-600x196.png" alt="" title="lvl2" width="600" height="196" class="aligncenter size-large wp-image-2219" /></a></p>
<p>As soon as the player sensor comes in contact with a sensor box using ID 99, it checks for its tag and sends a notification to the LevelChanger AIModel in the User AIModel Stack.</p>
<h2>Fading Away</h2>
<p>To make the level changing beautiful, we decided to employ a soft fading black screen and a loading image screen. You can create such an effect in numerous ways. We decided to use the least amount of code possible and instead do the heavy lifting in the HUD editor.</p>
<p>First, we need to create a new HUD (&#8220;BlackScreen&#8221;) with a screen-filling black label component. It will receive an action (&#8220;interpolateOpacity&#8221;) which we set as &#8220;Initial Action&#8221;. This way, the screen will fade to black as soon as the HUD is initialzed, no extra code necessary.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl4.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl4-600x201.png" alt="" title="lvl4" width="600" height="201" class="aligncenter size-large wp-image-2221" /></a></p>
<p>To fade back to the game, we created another HUD (&#8220;GameScreen&#8221;) that is almost identical to BlackScreen with the exception that the HUD action interpolates the opacity from 255 to 0 and not the other way around.</p>
<p>Later, a third HUD &#8220;LoadingScreen&#8221; is necessary, which displays the actual loading image or text, which is not animated.</p>
<h2>Level Changer</h2>
<p>The biggest chunk of logic for the level change is handled within the LevelChanger AIModel. It is a User AIModel that exists outside the scene and continues to run regardless of the events in the scene that is currently loaded. It essentially consists of two Events and two States with a number of helper functions and variables.</p>
<p>Once your player model has collided with the ID 99 box, the onChangeLevel() event is called, which sets the level changing process in motion:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl3.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl3-600x301.png" alt="" title="lvl3" width="600" height="301" class="aligncenter size-large wp-image-2220" /></a></p>
<h2>Starting and Stopping</h2>
<p>Once the LevelChanger AIModel has received the signal from the player model, a function called this.ChangeLevelFunction() is executed. This function initializes the BlackScreen HUD fade as well as the music fade &#8211; not how those things are done elegantly with just one call and not in a loop.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl7.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl7-600x249.png" alt="" title="lvl7" width="600" height="249" class="aligncenter size-large wp-image-2246" /></a></p>
<p>Furthermore, we call the AIModel itself to execute Event onLoadLevel after a delay of 1.5 seconds, which essentially switches states from this.Idle() to this.LevelChangerState().</p>
<p>It is a good idea to disable user input in the time of loading and during the fades. To do that, we need to send and Event notification to the Main User AI that handles all user inputs. You can either send an event that manipulates a variable inside the AI (as done in the example) or manipulate the AI variable directly using <em>user.setAIVariable ( hUser, sAIModel, sVariable, vValue )</em>.</p>
<p>Inside your Input AIModel, capturing keyboard events would have to be encapsulated like this:</p>

<div class="wp_syntax"><div class="code"><pre class="lua" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">--------------------------------------------------------------------------------</span>
<span style="color: #0000ff;">function</span> LevelChanger.onKeyboardKeyUp <span style="color: #66cc66;">&#40;</span> kKeyCode <span style="color: #66cc66;">&#41;</span>
<span style="color: #008000; font-style: italic;">--------------------------------------------------------------------------------</span>
&nbsp;
	<span style="color: #0000ff;">if</span> <span style="color: #0000ff;">this</span>.isUserInputEnabled<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #0000ff;">true</span> <span style="color: #0000ff;">then</span> <span style="color: #008000; font-style: italic;">-- only accept input if enabled</span>
		<span style="color: #008000; font-style: italic;">-- input your keystrokes here</span>
	<span style="color: #0000ff;">end</span>
&nbsp;
<span style="color: #008000; font-style: italic;">--------------------------------------------------------------------------------</span>
<span style="color: #0000ff;">end</span>
<span style="color: #008000; font-style: italic;">--------------------------------------------------------------------------------</span></pre></div></div>

<h2>A change in two States</h2>
<p>The LevelChanger AIModel has two states, Idle and LevelChangerState. Idle runs during the actual game, while LevelChangerState handles all the level loading things.</p>
<p>When you enter the level change, it is always a good idea to save the current game state before you load a new level, in case something goes wrong. This.AutoSave() is a dummy function that allows you to do just that. make sure you save everything you want to save in either a UserAI Table, some XML or an environment. </p>
<p><em>Tip: Save the new level string this.nextLevel(), so if you load up the save game, the new level will be loaded instead of the old one. At the end, the LoadingScreen HUD is initialized, which is in our case the LOADING sign. Modify that if you want to display images, hints, different text, and so forth.</em></p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl8.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl8-600x290.png" alt="" title="lvl8" width="600" height="290" class="aligncenter size-large wp-image-2235" /></a></p>
<p>onLoop handles the actual loading. Since most ShiVa scenes are rather small, we implemented a &#8220;grace second&#8221; &#8211; a timer that counts up into the variable this.loadingtimer until 1 second is over. This means that your loading screen will be visible for at least one full second.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl5.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl5-600x226.png" alt="" title="lvl5" width="600" height="226" class="aligncenter size-large wp-image-2233" /></a></p>
<p>When the state is left, we want to make sure to initialize the Hud that fades from black to the actual game and remove all unnecessary HUDs.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl6.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl6-600x291.png" alt="" title="lvl6" width="600" height="291" class="aligncenter size-large wp-image-2234" /></a></p>
<p>Once you finally get back into the gam (this.Idle() state), start the music again and, most importantly, re-enable the user input!</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl9.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/08/lvl9-600x306.png" alt="" title="lvl9" width="600" height="306" class="aligncenter size-large wp-image-2236" /></a></p>
<h2>Conclusion</h2>
<p>And there you have it, a simple yet effective and elegant way to change your scenes. To enhance it further, shorten loading times or even do a fancy loading bar, we suggest you look into the <a href="http://www.stonetrip.com/developer/doc/api/application-startCurrentUserScenePreloading">PreLoading</a> APIs. You will very likely have models that occur throughout the game, like guns, characters or items, if they are big, you should consider keeping them in memory all the time using the <a href="http://www.stonetrip.com/developer/doc/api/application-forceModelToStayLoaded">ForceLoad</a> APIs.</p>
<h3>Music Copyright</h3>
<p>The music files included in this example come from <a href="http://incompetech.com/m/c/royalty-free/index.html?genre=Polka">Kevin MacLeod/Inkompetech</a> and are <a href="http://creativecommons.org/licenses/by/3.0/">licensed under Creative Commons: By Attribution 3.0</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2217-elegant-level-changing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ShiVa Flash: JavaScript to AS3 to ShiVa</title>
		<link>http://www.shivaengine.com/developer/2157-shiva-flash-javascript-to-as3-to-shiva</link>
		<comments>http://www.shivaengine.com/developer/2157-shiva-flash-javascript-to-as3-to-shiva#comments</comments>
		<pubDate>Tue, 31 Jul 2012 08:11:11 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2157</guid>
		<description><![CDATA[Starting with the UAT 1.4 beta 4, the ShiVa Flash external interface has become feature complete. In this tutorial, we will learn how to manipulate a running ShiVa 3D FLASH application by calling DefaultUser-Events from html/js.]]></description>
			<content:encoded><![CDATA[<h2>ShiVa Setup</h2>
<p>In this tutorial, we will learn how to manipulate a running ShiVa 3D FLASH application by calling DefaultUser-Events. For our example, we have set up an event called <i>onProjectorEvent</i> in our main game AImodel that will change the projector map in our testgame.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/as3jsdemo1.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/as3jsdemo1-600x352.png" alt="" title="as3jsdemo1" width="600" height="352" class="aligncenter size-large wp-image-2158" /></a></p>
<p>Believe it or not, this is all that is required of you to do inside ShiVa. Export the game as STK with the DefaultTarget setting and you can close the Editor.</p>
<h2>UAT Project Build</h2>
<p>Export your game as STK and load it into the the UAT. in “Step 2″, choose “Project”:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_uat.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_uat-600x302.png" alt="" title="as3int_uat" width="600" height="302" class="aligncenter size-large wp-image-2096" /></a></p>
<h2>Making a HTML/Javascript Button</h2>
<p>We want to control the projector map with a button defined in html/js. Let&#8217;s open the HTML file that was generated by the project build, and add a button:</p>
<pre style="background-color:#ccc;magin:20px;">
&lt;button onclick=&quot;clicker();&quot;&gt;Outside ShiVa: Click this HTML button
to connect a js function to Flash to send a command to ShiVa!&lt;/button&gt;
</pre>
<p>Now we have to create a function &#8220;clicker()&#8221; that gets called once the button gets pressed. the JavaScript code for that is in the HEAD section of the document.</p>
<pre style="background-color:#ccc;magin:20px;">
&lt;!-- js bridge to flash and ultimately shiva --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	function clicker() {
		var flashObj = document.getElementById(&#39;Main&#39;);
		flashObj.sentfromjs();
	}
&lt;/script&gt;
</pre>
<p><i>&#8220;Main&#8221;</i> is the default ID for the ShiVa FLASH content, and <i>sentfromjs()</i> will be the function we capture inside our AS3 script.</p>
<h2>As3 External Interface and Callback</h2>
<p>In order to capture any JS input in AS3, we need to import the &#8220;external&#8221; library package at the bottom of the &#8220;import&#8221; list (line 14).</p>
<pre style="background-color:#ccc;magin:20px;">
import flash.external.*;
</pre>
<p>We have to initialize our callback once. I chose the <i>onEngineInitialized ( )</i> function and added the interface callback in line 122:</p>
<pre style="background-color:#ccc;magin:20px;">
private function onEngineInitialized ( ) : void
{
    	addEventListener ( Event.ENTER_FRAME, onEnterFrame ) ;
	//-- insert callback to receive command from js
	ExternalInterface.addCallback( "sentfromjs", sendmetoshiva );
}
</pre>
<p><i>&#8220;sentfromjs&#8221;</i> equals the function name in JS, while the second parameter <em>sendmetoshiva</em> is the name of the as3 function we will be calling. It&#8217;s time to write the <em>sendmetoshiva</em> function, where all the magic happens!</p>
<h2>Bridge.sendEventToDefaultUser</h2>
<p>The <em>public function sendmetoshiva ()</em> in line 171 calls Bridge.sendEventToDefaultUser, which is the function that bridges as3 with ShiVa. The prototype of that function is:</p>
<pre style="background-color:#ccc;magin:20px;">
public static function sendEventToDefaultUser (
_aimodel:String,
_handler:String,
_args:Array ) : void
</pre>
<p>While <em>_aimodel</em> and <em>_handler</em> are strings that refer to the Current User AImodel name and the contained handler respectively, <em>_args</em> is an array and follows the <em>onEngineEvent</em> rules for parameters:</p>
<pre style="background-color:#ccc;magin:20px;">
Bridge.sendEventToDefaultUser (
"SimpleProjector_Main",
"onProjectorEvent",
[kVarTypeString, "additional_arg_0", kVarTypeString, "additional_arg_1"] )

// for parameters: it follows the same rules as onEngineEvent:
// const kVarTypeNil       : int = 0 ;
// const kVarTypeNumber    : int = 1 ;
// const kVarTypeString    : int = 2 ;
// const kVarTypeBoolean	: int = 3 ;
// parameters come in pairs: first "type", then "value".
</pre>
<p>So, our <em>public function sendmetoshiva ()</em> in line 171 looks like this:</p>
<pre style="background-color:#ccc;magin:20px;">
public function sendmetoshiva () : void
{
Bridge.sendEventToDefaultUser ( "SimpleProjector_Main", "onProjectorEvent", null )
//no args to send
}
</pre>
<p>To pass arguments for JS to AS3, add parameters <em>sendmetoshiva ()</em>, like:</p>
<pre style="background-color:#ccc;magin:20px;">
public function sendmetoshiva (_s:String) : void
{
if _s == "something" {
Bridge.sendEventToDefaultUser ( "SimpleProjector_Main", "onProjectorEvent", null )
//no args to send, but we could send _s if we wanted
}
}
</pre>
<h2>Building the SWF application</h2>
<p>Run the BAT file in your project build directory to generate your SWF application.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_bat.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_bat-600x342.png" alt="" title="as3int_bat" width="600" height="342" class="aligncenter size-large wp-image-2093" /></a></p>
<p>It is recommended to open a CMD window first, CD to the project folder and run the BAT from there:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_cmd.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_cmd-600x646.png" alt="" title="as3int_cmd" width="600" height="646" class="aligncenter size-large wp-image-2094" /></a></p>
<h2>Demo Time</h2>
<p>Click the image below to play the example in your web browser!</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/images/flashsamples/as3jsdemo/" target="_blank"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/as3jsdemodemo-600x504.png" alt="" title="as3jsdemodemo" width="600" height="504" class="aligncenter size-large wp-image-2180" /></a></p>
<h2>Azoth Performance Boost</h2>
<p>With the latest flash built, we were able to boost performance by over 500%. Still, don’t forget to AZOTH your projects! Azoth is a Windows console (Win32 command-line) application that lets you replace method calls to a certain AS3 class (included with Azoth) with equivalent Alchemy opcodes in a SWF file. This provides even better performance for your game! Simply drag your game SWF onto the Azoth.exe binary and let it do its magic…</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_azoth.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_azoth-600x303.png" alt="" title="as3int_azoth" width="600" height="303" class="aligncenter size-large wp-image-2092" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2157-shiva-flash-javascript-to-as3-to-shiva/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Study: Babel Rising</title>
		<link>http://www.shivaengine.com/developer/2114-case-study-babel-rising</link>
		<comments>http://www.shivaengine.com/developer/2114-case-study-babel-rising#comments</comments>
		<pubDate>Thu, 05 Jul 2012 09:14:06 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2114</guid>
		<description><![CDATA[Are you curious about Babel Rising 3D, the latest cross platform hit made with ShiVa and published by Ubisoft? Michel and Damien from developer Mando Productions were nice enough to answer some of our questions regarding their latest game.]]></description>
			<content:encoded><![CDATA[<h2 style="margin-top:-10px;">Interview</h2>
<div align="center"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/unnamed.jpg" width="650" height="320" /></div>
<p><strong>Hello Michel and Damien! First of all, congratulations on your game Babel Rising! When I saw the first teaser some months ago, I was truly blown away by the artwork, the style, and the fun gameplay mechanics. Now that it finally has hit the store shelves, I think it is safe to say that you have created one of the coolest and best-looking ShiVa games yet. Babel Rising has just been released for XBLA and PSN as well as iOS and Android a few days ago, so not many users did have a chance to test it yet. Can you shortly introduce us to Babel Rising and tell us a little more about the game itself?</strong></p>
<p>Thanks of lot for your kind words. Babel Rising requested a lot of energy and passion during the last 12 months or so and we’re happy to see that the results looks nice. We’re keeping fingers crossed and are hoping the sales will be good.<br />
Babel Rising 3D is an action game where you step into the sacred sandals of a great, almighty, and very angry deity. As god, you can hurl bolts of holy lightning, summon punishing earthquakes, and unleash vengeful floods upon the foolish and irreverent Humans to prevent them from building the tower of Babel.  </p>
<p><strong>Babel rising boasts an impressive number of “firsts” for ShiVa: You have been working with the console ports of ShiVa that have not yet been officially released. Your game is the first to be distributed through XBLA and PSN,<br />
<a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/towersketch.jpg"  style="display: inline-block; float:left; margin:10px;margin-left:0px;"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/towersketch-300x194.jpg" alt="" title="towersketch" width="300" height="194" /></a>along with a multitude of other platforms. And with PlayStation Move and XBox Kinect, you integrate two cutting-edge technologies into the gameplay that have never been part of any ShiVa game. Can you share some insights about the development process of Babel Rising 3D?</strong></p>
<p>All in all, from the initial designs on paper and our early prototype, we’re talking nearly two years. But the production itself took us about 14 months, after ShiVa was chosen and the contract was signed. Mando’s core team had developed over 10 games on various platforms (PC and consoles) prior to Babel Rising 3D.</p>
<p>The game was entirely made by our studio. However, specific features were developed by Stonetrip on our request, and the cooperation between our team and Stonetrip was really very good. The biggest strength of ShiVa is the support from Stonetrip. Every time we hit a blocking point, we had very quickly at least a reply if not, most of the time, a new version of the engine either fixing the issue or adding the needed feature.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/towerdrawing.jpg"  style="display: inline-block; float:right; margin-left:10px;"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/towerdrawing-300x212.jpg" alt="" title="towerdrawing" width="300" height="212" /></a>Thanks to the plugin system, we managed to integrate PlayStation Move / Kinect on our own. PlayStation Move has been very easy to plug as we just had to port what we had already developed for another engine. Kinect being a more complex technology, more work has been required.</p>
<p><strong>Babel Rising is being published by one of the biggest names in gaming: Ubisoft. I know that a contract with them would be a dream come true for so many ShiVa users. Having such a giant backing development, one would think that you had all the resources in the world to make the game and use any engine you desire. Yet, you chose ShiVa. Why and when did you make that decision?</strong></p>
<p>First of all, we are very fortunate to work with Ubisoft on Babel Rising 3D. When we showed the prototype to the Ubisoft BizDev teams, they liked it almost immediately. Once the deal was signed and Ubisoft became our worldwide console and IOS publisher, their marketing, sales, and PR teams were also very enthusiastic. Ubisoft really is the best partner we could have for our game. In addition to Ubisoft, we are also working with a publisher specialized in the Android market, A.M.A for this specific version.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/harborsketch.jpg" style="display: inline-block; float:left; margin-right:10px;"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/harborsketch-300x194.jpg" alt="" title="harborsketch" width="300" height="194" class="alignleft size-medium wp-image-2115" /></a>We had a very interesting and constructive meeting with ShiVa’s CEO, Philip Belhassen, during GamesCom. He demonstrated the features of the engine to us and we had a good feeling about it from the start. Then we asked our lead developer, Damien, to evaluate the engine in depth, and his feedback was also very positive. The final decision was based half and half on pure technical aspects as well as the relationship quality. We knew that it would be a challenge for ShiVa as well, but the experience would be beneficial for both companies.<br style="clear:left;" /></p>
<p><strong><br />Browsing your website <a href="http://www.mandoproductions.com/">MandoProductions.com</a>, it seems that you have created a whole app universe around the old biblical story of the Tower of Babel. Babel Rising 3D does not seem to be the first game in the series. What can you tell us about its predecessors, and where do you plan on taking the series in the future?</strong></p>
<p>It all started two years ago with the original IOS Babel Rising game, in 2D. The idea was to play God and stop the humans in their attempt to build the Tower of Babel, using divine powers such as tornados, tsunamis or earthquakes.  We were lucky that the game did quite well. Building upon its success, we wanted to take the gameplay to the next level, so we started thinking about how we could enhance the gamer experience. Finally, we came up with the idea of a 3D version of the game, allowing the player to rotate around the tower and thus adding a strategic layer to the “arcade / action” mechanic. </p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/wave.png" style="display: inline-block; float:left; margin-right:10px;margin-bottom:20px;"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/wave.png" alt="" title="wave" width="320" height="480" /></a>While designing the basic player interface and the game world surroundings, we soon realized that the game was becoming too strategy-focused and had lost a lot of its simple “get rid of these pesky humans” fun. So we adjusted the style: Humans became bigger, the already “cartoony” world evolved even further in this direction, as the proportions between humans and buildings became more and more unrealistic.  At this stage, the core design was nearly finalized. We decided to develop a 3D playable prototype and… showed it to Ubisoft. They said yes!</p>
<p>Initially, Babel Rising was supposed to be the first opus in a series that we intended to call “The Adventures of God”. However, we decided that the “Babel Rising” universe was fun enough to be adapted in other game genres. So, someone in the team came up with the “Babel Running” idea. Despite killing all these poor workers, we wanted to show one of them carrying his stones to the yard and avoid God’s wrath. The game was released on IOS only a couple of weeks ago, and it’s too soon to tell if it’s going to be a success or not.</p>
<p>All versions of the game were made with ShiVa and this includes IOS, Android but also Windows Phone 7.</p>
<p><br style="clear:left;" /><strong>Thank you very much for the interview! We wish you all the best with Babel Rising 3D as well as your future endeavors!</strong></p>
<h2>Trailer</h2>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/pigHqFtw5sM" frameborder="0" allowfullscreen></iframe></p>
<h2>Get the Game</h2>
<p>Apple iOS AppStore: <a href="http://itunes.apple.com/nz/app/babel-rising-3d/id522047109?mt=8">Babel Rising 3D on the App Store</a><br />
Google Play / Android: <a href="https://play.google.com/store/apps/details?id=com.mando.babelrising3d">Babel Rising 3D on Android</a><br />
XBox Live Arcade: <a href="http://www.ubi.com/UK/Games/Info.aspx?pId=10519">Babel Rising 3D on XBLA</a><br />
PlayStation Network: <a href="http://www.ubi.com/UK/Games/Info.aspx?pId=10520">Babel Rising 3D on PSN</a><br />
Windows Phone coming in July</p>
<h2>About Mando Productions</h2>
<div align="center"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/07/mando.png" /></div>
<p>Mando is an independent game studio created in 2010. It consists of about twenty people who are managed by Michel Bams and Olivier Fontenay. The company works on creative and original projects for a multitude of platforms. Mando embraces the new digital distribution models as well as economic concepts (Free2Play, etc).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2114-case-study-babel-rising/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ShiVa Flash: ActionScript 3 Interaction</title>
		<link>http://www.shivaengine.com/developer/2087-shiva-flash-actionscript-3-interaction</link>
		<comments>http://www.shivaengine.com/developer/2087-shiva-flash-actionscript-3-interaction#comments</comments>
		<pubDate>Tue, 26 Jun 2012 07:08:29 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Export]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2087</guid>
		<description><![CDATA[Thanks to the UAT 1.4, you can now create project builds. Read this tutorial to learn how to modify ActionScript documents and add a whole new level of interactivity to your ShiVa Flash application!]]></description>
			<content:encoded><![CDATA[<h2>Project Builds</h2>
<p>With the latest Unified Authoring Tool 1.4, you gain the ability to generate project builds. Those will give you a lot more control over your source code files and allow you to modify them to fit your needs. With Flash project builds in particular, you can now edit .as documents. This opens the gates to a lot of fun&#8230; Let&#8217;s have a look at it!</p>
<h2>ShiVa Setup</h2>
<p>For our little demo scene, we have added a small HUD overlay with two buttons to the projector demo. Here is how they are arranged:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_hud.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_hud-600x325.png" alt="" title="as3int_hud" width="600" height="325" class="aligncenter size-large wp-image-2097" /></a></p>
<p>Now we need two handlers in the main AI that pick up the event:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_aim.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_aim-600x223.png" alt="" title="as3int_aim" width="600" height="223" class="aligncenter size-large wp-image-2089" /></a></p>
<p>The core function here is <strong>system.callClientFunction</strong>. The first argument, &#8220;onEngineEvent&#8221;, is mandatory &#8211; this will be the function in the ActionScript file we will change later. It is predefined. All other arguments can be chosen freely.</p>
<h2>UAT Project Build</h2>
<p>Export your game as STK and load it into the the UAT. in &#8220;Step 2&#8243;, choose &#8220;Project&#8221;:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_uat.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_uat-600x302.png" alt="" title="as3int_uat" width="600" height="302" class="aligncenter size-large wp-image-2096" /></a></p>
<h2>Fun with ActionScript</h2>
<p>You should now have a $mygame.as file in your protect directory. Open it up with a text editor of your choice.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_asfile.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_asfile-600x336.png" alt="" title="as3int_asfile" width="600" height="336" class="aligncenter size-large wp-image-2091" /></a></p>
<p>Scroll down to the function onEngineEvent. The interesting part is highlighted in the next picture:</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_as3.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_as3-600x636.png" alt="" title="as3int_as3" width="600" height="636" class="aligncenter size-large wp-image-2090" /></a></p>
<p>Have a good look at the comments in this file, they do explain a lot.</p>
<h2>Adding Functionality</h2>
<p>For this demo, we want to use AS3 to load an external picture onto our stage as well as create a button. First, we need to capture the event that we send from ShiVa. Let&#8217;s remember our system calls:</p>
<pre style="background-color:#ccc;magin:20px;">system.callClientFunction ("onEngineEvent", "as3button", "image")</pre>
<p>And the other one:</p>
<pre style="background-color:#ccc;magin:20px;">system.callClientFunction ("onEngineEvent", "as3button", "button")</pre>
<p>onEngineEvent is predefined and thus does not count. Both calls use as3button as first argument, they only differ in the second argument: button or image.</p>
<p>onEngineEvent expects its arguments in pairs. For instance, _args[0] and _args[1] both define the first argument, in our case, &#8220;as3button&#8221;. _args[0] holds the argument type (nil, number, string, boolean), while _args[1] holds its value (&#8220;as3button&#8221;). So, in order to solve our &#8220;button&#8221; and &#8220;image&#8221; problem, we need to look at _args[2] and _args[3], since we are dealing with the second argument of onEngineEvent.</p>
<pre style="background-color:#ccc;magin:20px;">if ( _args[2] == kVarTypeString )
{
    if ( _args[3] == "image" )
    {
    //...
    } 

    if ( _args[3] == "button" )
    {
    //...
    }
}
}</pre>
<p>If we were to return values, this scheme would apply to _returns:Array as well.</p>
<p>You can look up the code for displaying an image in the .as file that comes with the sources for this demo. It is important to remember that you have to draw your new image onto the stage using</p>
<pre style="background-color:#ccc;magin:20px;">stage.addChild</pre>
<p>Most AS3 resource sites will suggest addChild or this.addChild to you, which most likely will not work; use stage.*</p>
<p>In order to make the button change its state, we had to introduce a number of new functions into the AS3 file. Those are defined outside onEngineEvent, but inside the main class (in this case: public class FlashInteractionDemo_20120624)</p>
<pre style="background-color:#ccc;magin:20px;">		private function as3buttonClickHandler(event:MouseEvent):void
		{
			turnButtonGreen();
		}

               //...

		private function turnButtonGreen():void
		{
			as3demobutton.graphics.beginFill(0x008000);
			as3demobutton.graphics.drawRect(550, 300, 300, 80);
			as3demobutton.graphics.endFill();
		}</pre>
<p>These functions are responsible for changing the button color and managing its states. They can be found at the end of the .as file.</p>
<p>The image button uses a method called URLRequest. Compiling the script now will cause an error. You need to import the library that includes this method first. Therefor, in the top of the file, define</p>
<pre style="background-color:#ccc;magin:20px;">import flash.net.*;</pre>
<p>right under all the other includes that are already present.</p>
<p>The button sprite requires a variable declaration, you can find it on top of the main class.</p>
<pre style="background-color:#ccc;magin:20px;">private var as3demobutton:Sprite;</pre>
<h2>Building</h2>
<p>To compile and build your application, simply execute the BAT file that is provided in your project directory.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_bat.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_bat-600x342.png" alt="" title="as3int_bat" width="600" height="342" class="aligncenter size-large wp-image-2093" /></a></p>
<p>The CMD window closes as soon as the build is completed. Sadly, it also closes as soon as it encounters an error and does not give you enough time to read the error message. To fix this problem, open a CMD window from the Windows Start Menu, CD to your project directory, and drag the BAT file into this CMD window.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_cmd.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_cmd-600x646.png" alt="" title="as3int_cmd" width="600" height="646" class="aligncenter size-large wp-image-2094" /></a></p>
<h2>Demo Time</h2>
<p>Your project is now ready to go! Let&#8217;s have a look at the demo (click on the image to open a new tab):</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/images/flashsamples/as3/FlashInteractionDemo_20120624.html" target="_blank"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_demo-600x384.png" alt="" title="as3int_demo" width="600" height="384" class="aligncenter size-large wp-image-2095" /></a></p>
<h2>One more thing&#8230;</h2>
<p>Don&#8217;t forget to AZOTH your projects! Azoth is a Windows console (Win32 command-line) application that lets you replace method calls to a certain AS3 class (included with Azoth) with equivalent Alchemy opcodes in a SWF file. This provides superior performance for your game! Simply drag your game SWF onto the Azoth.exe binary and let it do its magic&#8230;</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_azoth.png"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/as3int_azoth-600x303.png" alt="" title="as3int_azoth" width="600" height="303" class="aligncenter size-large wp-image-2092" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2087-shiva-flash-actionscript-3-interaction/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ShiVa Flash: XML Highscore Example</title>
		<link>http://www.shivaengine.com/developer/2061-shiva-flash-xml-highscore-example</link>
		<comments>http://www.shivaengine.com/developer/2061-shiva-flash-xml-highscore-example#comments</comments>
		<pubDate>Tue, 12 Jun 2012 07:24:47 +0000</pubDate>
		<dc:creator>broozar</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.shivaengine.com/developer/?p=2061</guid>
		<description><![CDATA[Learn how to work with a remote high score list! Use ShiVa Flash to send XML data to a PHP script which stores your high scores on a distant server.]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>This tutorial is a follow-up to last week&#8217;s <a href="http://www.shivaengine.com/developer/2049-shiva-flash-xml-and-crossdomain">ShiVa Flash: XML and crossdomain.xml tutorial</a>. Today, we are programming a real-world example: We will be using the XML interface in order to store and receive a highscore list on a remote server.</p>
<h2>File Structure</h2>
<p>In order to make things work, you need to place the crossdomain.xml at the root level of your domain. Both highscore.php and highscore.xml have to be addressed from within your ShiVa application, you will need the full URL. The location of the SWF directory does not matter.</p>
<div style="margin:20px;"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/flashtree2.png" alt="" title="flashtree2" width="495" height="210" /></div>
<p>To learn more about the crossdomain.xml, please check last week&#8217;s <a href="http://www.shivaengine.com/developer/2049-shiva-flash-xml-and-crossdomain">ShiVa Flash: XML and crossdomain.xml tutorial</a>.</p>
<h2>Highscore XML Structure</h2>
<p>All high scores will be stored in a single XML file. It has the following structure:</p>
<pre style="background-color:#ccc;magin:20px;">
&lt;HighScore&gt;
&lt;entry name=&quot;Player 1&quot; score=&quot;0815&quot; date=&quot;2012-01-02&quot;/&gt;
&lt;entry name=&quot;Player 2&quot; score=&quot;0814&quot; date=&quot;2012-01-03&quot;/&gt;
&lt;entry name=&quot;Player 3&quot; score=&quot;0813&quot; date=&quot;2012-01-04&quot;/&gt;
&lt;entry name=&quot;Player 4&quot; score=&quot;0812&quot; date=&quot;2012-01-05&quot;/&gt;
&lt;entry name=&quot;Player 5&quot; score=&quot;0811&quot; date=&quot;2012-01-06&quot;/&gt;
&lt;/HighScore&gt;
</pre>
<p>To add our personal high score, we need to add a new &lt;entry /&gt; element to that list.</p>
<h2>ShiVa Send and Receive</h2>
<p>The whole sample works with a single user AI. Sending and Receiving is done using states, closely resembling <a href="http://www.shivaengine.com/developer/377-xml-manipulation">the ShiVa XML manipulation tutorial</a>.</p>
<p><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/flashai.png" alt="" title="flashai" width="370" height="682" class="alignnone size-full wp-image-2075" /></p>
<p>XML_PHP and XML_URL are public member variables that need to be adjusted to fit your server.</p>
<p>Clicking on the HUD buttons will send either a &#8220;onHUDButtonLoadXML&#8221; or a &#8220;onHUDButtonSendXML&#8221; event to the main user AI, which will call the states Send() and Receive() respectively.</p>
<h2>PHP Bridge</h2>
<p>The heart of the whole implementation is the PHP backbone script that receives, sorts, and writes all data into the highscore XML file. To keep things simple, this script does almost no error checking and should not be used as-is.</p>
<pre style="background-color:#ccc;magin:20px;">
&lt;?php

	//globals -----------------------------------------

	$filename = &quot;./highscore.xml&quot;;
	$linenum = 0;
	$newxmlarray=array();

	//read POST -----------------------------------------

if ( isset($_POST[&#39;STContent&#39;] ) ) {

	//new XML content sent from SHiVa
	$xml_add = stripslashes($_POST[&#39;STContent&#39;]);

	//get the score for sorting later on
	$grep = strpos( $xml_add, &quot;score=\&quot;&quot; );
	$newscore = substr( $xml_add, $grep+7, 4 );
</pre>
<p>After setting up some global variables, the script accepts the POST content. In a real game, make sure you check the input for validity! Next up, we will read the highscore.xml file into the cache, analyze all entries for the score and compare them to our new score. This replaces a sorting algorithm and though it is a little crude, it serves our purpose and is really fast.</p>
<pre style="background-color:#ccc;magin:20px;">
	//read xml to array -----------------------------------------

	$lines = file($filename);
	$countlines = count($lines);

	foreach($lines as $line) {

		//search for score, match only 4-figure numbers
		$moregrep = preg_match ( &#39;/&quot;[0-9]{4}&quot;/&#39;, $line ) ;

		if ($moregrep &gt; 0) {
			$grep = strpos( $line, &quot;score=\&quot;&quot; );
			$oldscore = substr ( $line, $grep+7, 4 );

			if ( intval($oldscore) &lt;= intval($newscore) ) {
				//found lesser score
				break;
			}
		}
	$linenum += 1;
	}
</pre>
<p>Now we have an entry point for the new XML line. Let&#8217;s compose the new XML and write it to disk:</p>
<pre style="background-color:#ccc;magin:20px;">
	//compose new XML order-----------------------------------

	for ( $k=0; $k&lt;$linenum; $k++ ) { $newxmlarray[] = $lines[$k]; }

	$newxmlarray[] = $xml_add.&quot;
&quot;; //add our new highscore, including a line break - important!

	for ( $j=$linenum; $j&lt;=$countlines-1; $j++ ) { $newxmlarray[] = $lines[$j]; }

	//write xml to disk-----------------------------------------

	if (is_writable($filename)) {
		$handle = fopen($filename, &#39;w&#39;);

		for ($j=0; $j&lt;count($newxmlarray); $j++) {
		    fwrite( $handle, $newxmlarray[$j] ) ;
		}

	    fclose($handle);

	}

	//-----------------------------------------

} else { echo &quot;Error.&quot;; }

?&gt;
</pre>
<h2>Flash Sample</h2>
<p>Click on the Image below to open a new window with a working ShiVa Flash Sample.</p>
<p><a href="http://www.shivaengine.com/developer/wp-content/images/flashsamples/xml/TEST_FlashXML.html" target="_blank"><img src="http://www.shivaengine.com/developer/wp-content/uploads/2012/06/flashhighscoresample-600x321.png" alt="" title="flashhighscoresample" width="600" height="321" class="aligncenter size-large wp-image-2070" /></a></p>
<p>Keep in mind that the Flash exporter is still BETA. Sometimes, the highscore list will not refresh instantly, but sending works every time! If you do not see any changes after sending, do not click wildly on the Send button, but wait for 30 seconds and then refresh the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shivaengine.com/developer/2061-shiva-flash-xml-highscore-example/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
