James Williams
LinkedInMastodonGithub

Exploring the PlayN APIs

In this post, I'll be covering an abbreviated view of the PlayN APIs. Generally, if you want to deploy an application to multiple platforms, you have to handle each platform individually or use a compromise solution like Apache Cordova (née PhoneGap). In many cases, you end with a solution that supports many platforms but looks a bit off as you are playing to a lowest common denominator.

PlayN uses a more robust Service Provider Interface approach by abstracting functionality in its core layer enhanced by platform specific implementations. The PlayN class provides accessors for assets, audio, graphics, interactions (pointers, mouse, and keyboard), networking, storage, and more.

The specific platforms, for example JavaPlatform and HtmlPlatform amongst others, after being registered with the function setPlatform(Platform platform)) provide the implementation details to execute the core code you write for your application.

playn.core.Game

The Game interface is your main entry point into your game. If you are lucky, most of your code will live here. A class implementing Game requires the following functions.

Function Description
void init() Called on initialization and used for general app setup
void paint(float alpha) Called each time game updates display, no logic should be here
void update(float delta) Game logic should be here
int updateRate() Frame update rate

In the next post, we'll explore how to put this knowledge to work in a small game.