Javascript SDK update for r96

For developers using the Construct 2 Javascript SDK

Post » Mon Jun 25, 2012 5:33 pm

Hi all,

There's a minor update to the Javascript SDK following r96. Click here to download it again:

http://www.scirra.com/downloads/javascript-sdk-template.zip

From the r96 changelog you may note the following performance item:

[quote]...the javascript code for actions, conditions and expressions not actually used in the project are now removed by Closure Compiler when exporting. This helps reduce the download size and improve startup time on mobile (since there is less javascript to parse).[/quote]

In order for unused conditions, actions and expressions to be removed by Closure Compiler, they have to be written with a slightly different syntax. The old style was this (only actions shown, it's the same for all three, and same for behaviors except using 'behaviorProto'):

[code]// Actions
pluginProto.acts = {};
var acts = pluginProto.acts;

acts.Action1 = function ()
{
     // ...
};

acts.Action2 = function ()
{
     // ...
};

// ...[/code]

Unfortunately Closure Compiler is not able to remove unused conditions, actions or expressions with this style of code. The new syntax is:

[code]// Actions
function Acts() {};

Acts.prototype.Action1 = function ()
{
     // ...
};

Acts.prototype.Action2 = function ()
{
     // ...
};

// ...

pluginProto.acts = new Acts();[/code]

This way has the same result at runtime, but Closure Compiler can remove unused conditions, actions or expressions. This helps keep the runtime slim since only functions your project actually uses are kept in the resulting javascript.

All official plugins and behaviors have already changed to the new style. Note the old style is backwards compatible and will continue to work at runtime just fine! You do not need to change old plugins. However, every single condition, action and expression will be included regardless of if they are actually used. Download the new SDK template and overwrite your current one if you've saved it, and this will make sure you use the new style for all future plugins.

Thanks for your help with plugin and behavior development!Ashley2012-06-25 17:33:19
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest