With Defold you can produce very lightweight and well-optimised builds, both mobile and HTML5 from the same sources.
One idea tickles my brain for the past few days - is it possible to produce Playable Ads with Defold? Playable Ads have self-explaining name - the ad you can play, technically they are tiny HTML5 games. I heard such ads have very good conversions rates, so just imagine - you build iOS/Android game and with cost of pressing few buttons also build a Playable Ad for it, from the same sources. Sounds intriguing!
And not so long ago Facebook added the ability to upload playables to their system. Here are requirements, some important points:
Playable should not require mraid.js.
A single file for playable ad that contains all assets as part of that single HTML file and assets should be data URI compressed. (Javascript, CSS, images, sounds).
Playable asset size should be less than 2 MB.
No dynamic asset loading through external network is permitted.
Tips for combining into one file-encode image into base64 string, integrate js into index.html.
Playable HTML5 should not contain any JS redirect.
Playable should not make any HTTP request.
I’m not very familiar with Defold’s HTML5 tech stack, is there any requirement impossible to reach with Defold?
Sure, it’s possible. You need to strip the engine from anything you don’t need, use texture compression and in general be very smart with the assets you use. And create a script that takes care of packaging the whole thing in a single .html file.
I’m back on this again. Ok, I see how to inline css and js into html-file, need to rework such pieces of code:
function load_engine() {
var engineJS = document.createElement('script');
engineJS.type = 'text/javascript';
if (Module['isWASMSupported']) {
engineJS.src = 'PlayableAd_wasm.js';
} else {
engineJS.src = 'PlayableAd_asmjs.js';
}
document.head.appendChild(engineJS);
}
That’s clear. But I don’t fully understand how Defold packs assets for HTML5, like images, fonts, sounds etc? Can’t find anything related in the docs. As I see there is archive folder:
And I’m not 100% sure what it does… gives the reference to function returning path to file in archive… so, how can I inline this stuff into my resulting HTML? is it ever possible?
Aha, I found where this path-function parameter is used in dmloader.js, later archive-files seem to be loaded via HTTPRequest. Code is not obfuscated or minified here, so I believe I can rewrite it to work as I need. I’ll put updates with the progress here, thanks!
Wow! It works! I’ve used it on “Linker” sample project, there is a resulting one-html-file http://anvil-games.com/defold/ad/playable_ad.html, it weights 2.4mb and canvas scaling need to be fixed, but in common script worked like a charm, thanks!
The only thing was to change “projectTitle” in “gulp file.js”
I’ve removed all sounds and music, throw away some sprites to reduce the size of atlas and came up with 2.4mb build size. Then played around with compression settings in texture_profile but this did not show a significant changes, but limiting the “Max Texture Size” did the trick (and as for 2mb ad the resulting quality is ok imo) - 1.99mb
You can check it in the Facebook Feed by this link: Redirecting... (seems to be working only in FB mobile app; and I don’t know for how long the link will be working)
But I’ve noticed some major FPS drops in it and probably right now the ad does not provide a good user experience because of lags. So I need to check this.
UPD: fixed lags by setting “Contact Impulse Limit” in physics settings
The first test with Playable Ad finished, so, just want to confirm, that it was not banned or reported by users or something else, and for sure it was successful for the game:
“Results” here are “App Installs”, on iOS, in USA. You can see, that Cost Per Install was TWICE lower in comparison with a simple video on the same audience and placements! Well, my best CPI with video ad was around $0.7, so if be more precise, the win from playable ad was “only” 50% and not 100%. But still - very promising and inspiring!
git clone https://github.com/aglitchman/defold-playable-ads.git
cd defold-playable-ads
npm install
gulp
Everything works, then I start a local http python -s SimpleHTTPServer 8080
I get a blank page and an error console:
Uncaught TypeError: Cannot read property 'parentElement' of undefined
at Object.removeProgress (dmloader.js:450)
at Object._preloadAndCallMain (dmloader.js:824)
at Array.onArchiveLoaded (dmloader.js:720)
at Object.notifyListeners (dmloader.js:213)
at Object.notifyArchiveLoaded (dmloader.js:235)
at Object.onArchiveLoaded (dmloader.js:406)
at Object.onFileLoaded (dmloader.js:398)
at Object.onPieceLoaded (dmloader.js:346)
at dmloader.js:318
at request.onload (dmloader.js:91)