Skip to content

Instantly share code, notes, and snippets.

@foobraco
Created June 25, 2012 16:00
Show Gist options
  • Save foobraco/2989431 to your computer and use it in GitHub Desktop.
Save foobraco/2989431 to your computer and use it in GitHub Desktop.
How to create platform specific interfaces in PlayN
public static interface myInterface {
void closeapp();
void callvibrator(long miliduration);
}
public final myInterface myinterface;
public Dig(myInterface myinterface) {
this.myinterface = myinterface;
}
/*
And that's it, now you can call anywhere in your core the function callvibrator(100);
and it will activate the vibrator on android platform.
This example works with android only but it should't be much different in the other platforms.
*/
final MyGame mygame = new MyGame(new AndroidCode());
public class AndroidImplementation implements MyGame.myInterface {
@Override
public void closeapp() {
System.exit(0);
}
@Override
public void callvibrator(long miliduration) {
vib.vibrate(miliduration);
}
}
// and where you usually call PlayN.run(new MyGame()); now call
Playn.run(mygame new AndroidImplementation())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment