hypersurge / fbinstant-haxe

Haxe externs for Facebook Instant Games SDK
MIT License
8 stars 2 forks source link

Tutorial to use this extension #1

Open stein-D opened 5 years ago

stein-D commented 5 years ago

Hello, can you provide tutorial how to use this extension?

hypersurge commented 5 years ago

Hello, what did you have in mind? Are you already familiar with Facebook Instant Game SDK? If not I'd suggest starting with their documentation:

https://developers.facebook.com/docs/games/instant-games

If you are familiar with the FBIG SDK / API then connecting it up with your game will likely depend on what HTML5 libraries you are using (Haxe or otherwise).

nanhuichen commented 5 years ago

Hello,

Thanks for your extension. But there are Interfaces only, how to start with extern Interface?

Don't we make class to implement it?

hypersurge commented 5 years ago

I recommend following the Quick Start guide on Facebook's IG developer pages: https://developers.facebook.com/docs/games/instant-games/getting-started/quickstart

The result of which is we have an index.html with the Facebook SDK imported / loaded. Loading the SDK is sufficient to instantiate the top level "fbinstant" object which provides the Javascript functions we want to access (nearly all are asynchronous and use promises).

From a Haxe perspective we type this top level object to the IFBInstant interface from the externs available in this "fbinstant" library - for example: var fbinstant:fbinstant.IFBInstant = untyped js.Browser.window.FBInstant;

All other methods and properties are accessible directly from that.

Additionally creating a Haxe class that encapsulates all this might be a good design choice for your project? This is what we do, but it is not included in this library because we only use a subset of the SDK and our requirements may not match your own. Such a helper class may also want to consider loading a mock SDK for localhost development (as the localhost development options provided by Facebook can be slow).

nanhuichen commented 5 years ago

Thanks for your response.

Yes, I make a template of html like this: image

And haxe code:

#if (js && html5)
var fbInstant:IFBInstant = untyped __js__('window.FBInstant');
#end

It's awesome.

hypersurge commented 5 years ago

Good! Just be aware that startGameAsync should occur after (game) loader is complete, and that (game) loading progress should be communicated to FBInstant via setLoadingProgress(). So the chain of methods goes: initializeAsync, setLoadingProgress, startGameAsync, ...

nanhuichen commented 5 years ago

@hypersurge Thanks for your tips. I like custom progress bar better. image

hypersurge commented 5 years ago

Please let us know if Facebook accept that (last I saw was rejection for apps that don't implement setLoadingProgress).