SlideShare a Scribd company logo
1 of 51
Developing multi-platform games
with PlayN Java framework
Joint meeting of Central California Java User Group
and GDG Fresno, 01/08/2015,Bitwise Industries
Presenter: Csaba Toth,
Csaba Technology Services LLC
Agenda
• Outlook of the topic and history of PlayN
• Introduction to PlayN, basic concepts
• Technical details
• Triple Play framework
• Showcase of a real-world application
• Thoughts for future
Game and UI development in Java
• JavaFX 3D
• LWJGL (Lightweight Java Game Library)
– Open source, exposes OpenGL, OpenAL, OpenCL
– http://www.lwjgl.org/
• PlayN
• + Triple Play
PlayN – History
• open source Java software framework
• Apache License
• intended to create multi-platform games
• Motto: “Cross platform game library for N>=5
platforms”
• Started in January 2011named as ForPlay
– Library built on top of GWT
PlayN – History
• 2011 Google I/O
• Important person from Google: Lilli Thompson
• In August 2011 the project was forked and rebranded
as PlayN
• Backed up by Google for some years
• Used by Chrome version of Angry Birds
• Google now “abandoned” it, Three Rings gaming studio
put a lot of effort (more about TriplePlay later)
Familiar Tools
• Box2D: C++ 2D Physics engine by Erin Catto
• JBox2D: Java port of Box2D
• GWTBox2D: JS port via GWT
(GWT – Google Web Toolkit)
• Open source set of tools
• Write JavaScript front-end applications in Java
• Used as a front-end by some Java EE solutions
– (GWT + ExtJS, GXT)
(GWT – Google Web Toolkit)
• Advantages
– Removes unused code
– Compile time checking
– Inlines, optimizes
– Obfuscates output
– Adjusted for browser quirks
• Disadvantage: not all Java libraries can be
compiled by GWT, in fact it’s very limited!
PlayN – platform
• Java SE - native
• HTML 5 – using GWT
• Flash – not really functional any more AFAIK
• Android – almost native Java
• iOS – using Xamarin framework + Visual Studio
– Upcoming: using RoboVM
PlayN platforms
• All Java code you write should be able to be
consumed by GWT compilation and also
Android dexer
HTML5
• WebGL
• Canvas2D
• CSS3
• Web Audio API
• Most of the PlayN platform implementations
try to support hardware acceleration
Attribution
• A bunch of slide material from Lilli
• Used some material from Michael Twohey,
member of our project and Team Bad Wolf
• Deal-O-Round project (Team Bad Wolf)
PlayN API
• Keep core small
Components of PlayN
The Game Loop
• Implement PlayN.Game
public class MyGame implements Game {
public void init() {
// initialize game.
}
public void update (float delta) {
// update world.
}
public void paint (float alpha) {
// render world.
}
}
Rendering
// Each device has different screen parameters
// Resize to the available resolution on the current device.
graphics().setSize(
graphics().screenWidth(),
graphics().screenHeight()
);
// Keep the same aspect ratio.
float sx = graphics().screenWidth() / (float) WIDTH;
float sy = graphics().screenHeight() / (float) HEIGHT;
// Fit to the available screen without stretching.
graphics().rootLayer().setScale(Math.min(sx, sy));
Drawing API
Layer System
Layer types
• Layers have distinct sizes and transforms
• Used to optimize
SurfaceLayer
• Traditional rendering paradigm
• Render multiple images into a single surface
• Clear each frame
// Clear the surface.
surface.clear();
// Draw an image into the surface.
surface.drawImage(myImage, x, y);
// Draw a scaled subsection of the source image into the surface.
surface.drawImage(image, dx, dy, dw, dh, sx, sy, sw, sh);
GroupLayer
ImageLayer
• Fire and forget image
• Don't need to draw in paint()
• Render images not in scenegraph
• UI, logos, overlays
CanvasLayer
• Mirrors much of the HTML5 canvas API
• Procedural circle, rect, line, point, gradient...
• Text rendering
• Slow
canvas.setFillColor(Color.rgb(100, 255, 0));
canvas.fillCircle(x, y, r);
canvas.fillRect(x, y, w, h);
canvas.drawImage(myImage, x, y);
canvas.drawText("Hello text!", x, y);
canvas.drawLine(x0, y0, x1, y1);
Layers recap
• 3/4 layer types can draw images
• SurfaceLayer for standard sprite rendering
• GroupLayer for organization
• ImageLayer for static images
• CanvasLayer for procedural drawing
Transforms and surfaces
// Like OpenGL push.
surface.save();
surface.translate(p.x, p.y);
surface.rotate(p.r);
surface.scale(p.sx, p.sy);
// Draw something at transformed coordinates!
// Like OpenGL pop.
surface.restore();
IO System: Platform Abstractions
• Pointer
– Most general screen event
Works everywhere
• Mouse
– Left, right, mid buttons & wheel
• Touch
– Pressure, size, multitouch
IO System
• Input devices
pointer().setListener(new Pointer.Adapter() {
public void onPointerStart(Pointer.Event event) {
// Handle mouse down event.
}
// ...Same pattern for onPointerEnd, onPointerDrag
});
keyboard().setListener(new Keyboard.Adapter() {
public void onKeyDown(Event event) {
// Handle key down event.
}
// ... Same pattern for onKeyUp
});
Cross platform input
• Support touch-based zoom where available
import static playn.core.PlayN.platformType;
if (platformType().equals(Platform.Type.ANDROID)) {
touch().setListener(new Touch.Adapter() {
@Override
public void onTouchStart(Event[] touches) {
// Process touch events into a zoom start position.
}
@Override
public void onTouchMove(Event[] touches) {
// Update zoom based on touches.
}
});
}
Asset Management
• Abstraction for platform-specific resource fetching
public interface AssetManager {
Image getImage(String path);
Sound getSound(String path);
void getText(String path, ResourceCallback callback);
boolean isDone();
int getPendingRequestCount();
}
Loading Images
• Abstraction for platform-specific resource fetching
// Ask the Asset Manager to create a new image.
Image image = assetManager().getImage("myImage.png");
// Specify an onLoaded callback.
image.addCallback(new ResourceCallback() {
public void done(Image image) {
// handle new image.
}
}
// To draw the image that was loaded, render it to a layer.
mySurfaceLayer.surface().drawImage(image, x, y);
Asset Watchers
• Make sure everything is loaded before you start the game
AssetWatcher watcher = new AssetWatcher(new Listener() {
public void done() {
startGame();
}
});
// Add assets to check.
watcher.add(image1);
watcher.add(image2);
// ...
// Start the watching now.
watcher.start();
Sounds
• Use PlayN.core.Sound() abstraction
• HTML5 version uses Web Audio API via gwt-voices
public interface Sound {
boolean play();
void stop();
void setLooping(boolean looping);
void setVolume(float volume);
boolean isPlaying();
}
assetManager().getSound("mySound.mp3");
Storage
• 5MB max due to HTML5 local storage limits
• Strings only (for now)
/** Abstraction for Storage across platforms. */
public interface Storage {
public void setItem(String key, String data);
public void removeItem(String key);
public String getItem(String key);
// Returns true if the Storage data will be persisted across restarts.
public boolean isPersisted();
}
Saving data
JSON loading
• JSON implementation is platform specific
PlayN.assetManager().getText(JSON_FILE, new ResourceCallback() {
@Override
public void done(String resource) {
Json.Object json = PlayN.json().parse(resource);
Json.Array myArray = json.getArray("myArray");
int myInt = json.getInt("myInt");
}
@Override
public void error(Throwable err) {
PlayN.log().error("Failed to load: " + err.getMessage());
}
});
JSON saving
Writer writer = PlayN.json().newWriter();
writer.object();
writer.key("myInt");
writer.value(123);
writer.key("myArray");
writer.array();
for (String s : arrayOfStringParams) {
writer.value(s);
}
writer.endArray();
writer.endObject();
String output = writer.write();
Recap so far
• Main game loop
• Render efficiently
• Handle input
• Load assets
• Play audio
• Save data
Extras
• Even in-app payment is supported in platform
independent API
Links
• Mike Twohey’s presentation:
https://drive.google.com/file/d/0Bx6U-
HF_yP7qcWdiRXdCdTQyams/view
• Lilli’s presentation:
– http://playn-2011.appspot.com/
• Chris Mohritz presentation, good hands-on lab:
http://www.slideshare.net/ChrisMohritz/building-crossplatform-
games-with-google-playn-14294882
• Where to start:
– https://code.google.com/p/playn/wiki/GettingStarted
– https://developers.google.com/playn
We are not done yet at all
• How to draw menus, buttons, texts?
– We can draw texts, but what about buttons and widgets?
• Answer: Triple Play
– https://github.com/threerings/tripleplay
– https://github.com/threerings/playn
– collection of game-related utility classes that can be used with
the PlayN library
– Layouting engine
– Widget set (buttons, labels, sliders, …)
– Formatting
What you need
• Eclipse IDE with Android plugins
• Maven build system
• M2E plugin for Eclipse
• Extremely easily scaffold a skeleton with a Maven archetype:
mvn archetype:generate
-DarchetypeGroupId=com.googlecode.playn
-DarchetypeArtifactId=playn-archetype -DarchetypeVersion=1.8
Showcase: Deal-O-Round
• Team Bad Wolf was formed for 59
Days of Code
– Csaba Toth, Michael Twohey, Tim
Yopp, Vernon Burt
• Deal-O-Round is a card game
• Uses PlayN framework
• https://dealoround.com
Showcase: Deal-O-Round
• Launched June 17th,
2014 on Google Play
• Free, ad supported
• Early phase
prototype, sketch:
Demo
• File structure
• Implementation
details
Sprites
• Cardsprites1366.png
• Cardsprites1366.json
• BoardScene.java:390
Graphics
• Diamond
• Menu
• Spin
Touch Input
• onPointerStart
• onPointerDrag
• onPointerEnd
• Button
• Debug coordinates
Other
• Mp3 music
• Spin
• Timer
• Networking
• Android
• Scoring poker hands
Experiences
• PlayN is not as popular as Unity or certain other frameworks,
sometimes hard to get help
• Having the common denominator has restrictions: either you use
the PlayN multi platform APIs, or you have to develop platform
specific code
– OAuth authentication code, networking – won’t go through GWT
compilation phase
• Preferable for 2D games
• Hopefully RoboVM will cause a new momentum
• https://code.google.com/p/playn/w/list
Future
• http://www.robovm.com/
• Will provide Java support for iOS (and Android)
• Two developers started it back in 2013
• Oracle featured them and will back them up
• PlayN picks it up too
• Will provide a much straight path to iOS port than
Xamarin/.NET/Visual Studio
• 1.9 PlayN version is under development
Thanks for coming!
• Questions?

More Related Content

Similar to Developing multi-platform games with PlayN Java framework

Developing VR Experiences with Unity
Developing VR Experiences with UnityDeveloping VR Experiences with Unity
Developing VR Experiences with UnityMark Billinghurst
 
Improving Game Performance in the Browser
Improving Game Performance in the BrowserImproving Game Performance in the Browser
Improving Game Performance in the BrowserFITC
 
Desktop apps with node webkit
Desktop apps with node webkitDesktop apps with node webkit
Desktop apps with node webkitPaul Jensen
 
Html5 Game Development with Canvas
Html5 Game Development with CanvasHtml5 Game Development with Canvas
Html5 Game Development with CanvasPham Huy Tung
 
Adventures in cross platform ConnectJS / TiConnect 2014
Adventures in cross platform ConnectJS / TiConnect 2014Adventures in cross platform ConnectJS / TiConnect 2014
Adventures in cross platform ConnectJS / TiConnect 2014Jason Kneen
 
Workingwithunity 110519054824-phpapp01
Workingwithunity 110519054824-phpapp01Workingwithunity 110519054824-phpapp01
Workingwithunity 110519054824-phpapp01Srijib Roy
 
Doug McCune - Using Open Source Flex and ActionScript Projects
Doug McCune - Using Open Source Flex and ActionScript ProjectsDoug McCune - Using Open Source Flex and ActionScript Projects
Doug McCune - Using Open Source Flex and ActionScript ProjectsDoug McCune
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
Building GPU-Accelerated Mobile Application Interfaces with Starling and Feat...
Building GPU-Accelerated Mobile Application Interfaces with Starling and Feat...Building GPU-Accelerated Mobile Application Interfaces with Starling and Feat...
Building GPU-Accelerated Mobile Application Interfaces with Starling and Feat...Joseph Labrecque
 
Why Javascript matters
Why Javascript mattersWhy Javascript matters
Why Javascript mattersMarko Heijnen
 
Using Adobe Gaming Tools for Education
Using Adobe Gaming Tools for EducationUsing Adobe Gaming Tools for Education
Using Adobe Gaming Tools for EducationJoseph Labrecque
 
HoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOpsHoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOpsSarah Sexton
 
Appcelerator Titanium Intro
Appcelerator Titanium IntroAppcelerator Titanium Intro
Appcelerator Titanium IntroNicholas Jansma
 
Fii Practic Frontend - BeeNear - laborator 4
Fii Practic Frontend - BeeNear - laborator 4Fii Practic Frontend - BeeNear - laborator 4
Fii Practic Frontend - BeeNear - laborator 4BeeNear
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsLuca Galli
 
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4benko
 
W3C HTML5 KIG-The complete guide to building html5 games
W3C HTML5 KIG-The complete guide to building html5 gamesW3C HTML5 KIG-The complete guide to building html5 games
W3C HTML5 KIG-The complete guide to building html5 gamesChanghwan Yi
 

Similar to Developing multi-platform games with PlayN Java framework (20)

Soc research
Soc researchSoc research
Soc research
 
Developing VR Experiences with Unity
Developing VR Experiences with UnityDeveloping VR Experiences with Unity
Developing VR Experiences with Unity
 
Improving Game Performance in the Browser
Improving Game Performance in the BrowserImproving Game Performance in the Browser
Improving Game Performance in the Browser
 
Desktop apps with node webkit
Desktop apps with node webkitDesktop apps with node webkit
Desktop apps with node webkit
 
Html5 Game Development with Canvas
Html5 Game Development with CanvasHtml5 Game Development with Canvas
Html5 Game Development with Canvas
 
Adventures in cross platform ConnectJS / TiConnect 2014
Adventures in cross platform ConnectJS / TiConnect 2014Adventures in cross platform ConnectJS / TiConnect 2014
Adventures in cross platform ConnectJS / TiConnect 2014
 
Workingwithunity 110519054824-phpapp01
Workingwithunity 110519054824-phpapp01Workingwithunity 110519054824-phpapp01
Workingwithunity 110519054824-phpapp01
 
React nativebeginner1
React nativebeginner1React nativebeginner1
React nativebeginner1
 
Doug McCune - Using Open Source Flex and ActionScript Projects
Doug McCune - Using Open Source Flex and ActionScript ProjectsDoug McCune - Using Open Source Flex and ActionScript Projects
Doug McCune - Using Open Source Flex and ActionScript Projects
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
Building GPU-Accelerated Mobile Application Interfaces with Starling and Feat...
Building GPU-Accelerated Mobile Application Interfaces with Starling and Feat...Building GPU-Accelerated Mobile Application Interfaces with Starling and Feat...
Building GPU-Accelerated Mobile Application Interfaces with Starling and Feat...
 
Why Javascript matters
Why Javascript mattersWhy Javascript matters
Why Javascript matters
 
Using Adobe Gaming Tools for Education
Using Adobe Gaming Tools for EducationUsing Adobe Gaming Tools for Education
Using Adobe Gaming Tools for Education
 
HoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOpsHoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOps
 
Appcelerator Titanium Intro
Appcelerator Titanium IntroAppcelerator Titanium Intro
Appcelerator Titanium Intro
 
Fii Practic Frontend - BeeNear - laborator 4
Fii Practic Frontend - BeeNear - laborator 4Fii Practic Frontend - BeeNear - laborator 4
Fii Practic Frontend - BeeNear - laborator 4
 
Mobile native-hacks
Mobile native-hacksMobile native-hacks
Mobile native-hacks
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact js
 
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
 
W3C HTML5 KIG-The complete guide to building html5 games
W3C HTML5 KIG-The complete guide to building html5 gamesW3C HTML5 KIG-The complete guide to building html5 games
W3C HTML5 KIG-The complete guide to building html5 games
 

More from Csaba Toth

Git, GitHub gh-pages and static websites
Git, GitHub gh-pages and static websitesGit, GitHub gh-pages and static websites
Git, GitHub gh-pages and static websitesCsaba Toth
 
Eclipse RCP Demo
Eclipse RCP DemoEclipse RCP Demo
Eclipse RCP DemoCsaba Toth
 
The Health of Networks
The Health of NetworksThe Health of Networks
The Health of NetworksCsaba Toth
 
Introduction to Google BigQuery
Introduction to Google BigQueryIntroduction to Google BigQuery
Introduction to Google BigQueryCsaba Toth
 
Column Stores and Google BigQuery
Column Stores and Google BigQueryColumn Stores and Google BigQuery
Column Stores and Google BigQueryCsaba Toth
 
Windows 10 preview
Windows 10 previewWindows 10 preview
Windows 10 previewCsaba Toth
 
Trends and future of java
Trends and future of javaTrends and future of java
Trends and future of javaCsaba Toth
 
Google Compute Engine
Google Compute EngineGoogle Compute Engine
Google Compute EngineCsaba Toth
 
Google App Engine
Google App EngineGoogle App Engine
Google App EngineCsaba Toth
 
Setting up a free open source java e-commerce website
Setting up a free open source java e-commerce websiteSetting up a free open source java e-commerce website
Setting up a free open source java e-commerce websiteCsaba Toth
 
CCJUG inaugural meeting and Adopt a JSR
CCJUG inaugural meeting and Adopt a JSRCCJUG inaugural meeting and Adopt a JSR
CCJUG inaugural meeting and Adopt a JSRCsaba Toth
 
Google Cloud Platform, Compute Engine, and App Engine
Google Cloud Platform, Compute Engine, and App EngineGoogle Cloud Platform, Compute Engine, and App Engine
Google Cloud Platform, Compute Engine, and App EngineCsaba Toth
 
Hive and Pig for .NET User Group
Hive and Pig for .NET User GroupHive and Pig for .NET User Group
Hive and Pig for .NET User GroupCsaba Toth
 
Hadoop and Mapreduce for .NET User Group
Hadoop and Mapreduce for .NET User GroupHadoop and Mapreduce for .NET User Group
Hadoop and Mapreduce for .NET User GroupCsaba Toth
 
Introduction to Hadoop and MapReduce
Introduction to Hadoop and MapReduceIntroduction to Hadoop and MapReduce
Introduction to Hadoop and MapReduceCsaba Toth
 
Introduction into windows 8 application development
Introduction into windows 8 application developmentIntroduction into windows 8 application development
Introduction into windows 8 application developmentCsaba Toth
 
Ups and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research settingUps and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research settingCsaba Toth
 
Adopt a JSR NJUG edition
Adopt a JSR NJUG editionAdopt a JSR NJUG edition
Adopt a JSR NJUG editionCsaba Toth
 

More from Csaba Toth (18)

Git, GitHub gh-pages and static websites
Git, GitHub gh-pages and static websitesGit, GitHub gh-pages and static websites
Git, GitHub gh-pages and static websites
 
Eclipse RCP Demo
Eclipse RCP DemoEclipse RCP Demo
Eclipse RCP Demo
 
The Health of Networks
The Health of NetworksThe Health of Networks
The Health of Networks
 
Introduction to Google BigQuery
Introduction to Google BigQueryIntroduction to Google BigQuery
Introduction to Google BigQuery
 
Column Stores and Google BigQuery
Column Stores and Google BigQueryColumn Stores and Google BigQuery
Column Stores and Google BigQuery
 
Windows 10 preview
Windows 10 previewWindows 10 preview
Windows 10 preview
 
Trends and future of java
Trends and future of javaTrends and future of java
Trends and future of java
 
Google Compute Engine
Google Compute EngineGoogle Compute Engine
Google Compute Engine
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
Setting up a free open source java e-commerce website
Setting up a free open source java e-commerce websiteSetting up a free open source java e-commerce website
Setting up a free open source java e-commerce website
 
CCJUG inaugural meeting and Adopt a JSR
CCJUG inaugural meeting and Adopt a JSRCCJUG inaugural meeting and Adopt a JSR
CCJUG inaugural meeting and Adopt a JSR
 
Google Cloud Platform, Compute Engine, and App Engine
Google Cloud Platform, Compute Engine, and App EngineGoogle Cloud Platform, Compute Engine, and App Engine
Google Cloud Platform, Compute Engine, and App Engine
 
Hive and Pig for .NET User Group
Hive and Pig for .NET User GroupHive and Pig for .NET User Group
Hive and Pig for .NET User Group
 
Hadoop and Mapreduce for .NET User Group
Hadoop and Mapreduce for .NET User GroupHadoop and Mapreduce for .NET User Group
Hadoop and Mapreduce for .NET User Group
 
Introduction to Hadoop and MapReduce
Introduction to Hadoop and MapReduceIntroduction to Hadoop and MapReduce
Introduction to Hadoop and MapReduce
 
Introduction into windows 8 application development
Introduction into windows 8 application developmentIntroduction into windows 8 application development
Introduction into windows 8 application development
 
Ups and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research settingUps and downs of enterprise Java app in a research setting
Ups and downs of enterprise Java app in a research setting
 
Adopt a JSR NJUG edition
Adopt a JSR NJUG editionAdopt a JSR NJUG edition
Adopt a JSR NJUG edition
 

Recently uploaded

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 

Recently uploaded (20)

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 

Developing multi-platform games with PlayN Java framework

  • 1. Developing multi-platform games with PlayN Java framework Joint meeting of Central California Java User Group and GDG Fresno, 01/08/2015,Bitwise Industries Presenter: Csaba Toth, Csaba Technology Services LLC
  • 2. Agenda • Outlook of the topic and history of PlayN • Introduction to PlayN, basic concepts • Technical details • Triple Play framework • Showcase of a real-world application • Thoughts for future
  • 3. Game and UI development in Java • JavaFX 3D • LWJGL (Lightweight Java Game Library) – Open source, exposes OpenGL, OpenAL, OpenCL – http://www.lwjgl.org/ • PlayN • + Triple Play
  • 4. PlayN – History • open source Java software framework • Apache License • intended to create multi-platform games • Motto: “Cross platform game library for N>=5 platforms” • Started in January 2011named as ForPlay – Library built on top of GWT
  • 5. PlayN – History • 2011 Google I/O • Important person from Google: Lilli Thompson • In August 2011 the project was forked and rebranded as PlayN • Backed up by Google for some years • Used by Chrome version of Angry Birds • Google now “abandoned” it, Three Rings gaming studio put a lot of effort (more about TriplePlay later)
  • 6. Familiar Tools • Box2D: C++ 2D Physics engine by Erin Catto • JBox2D: Java port of Box2D • GWTBox2D: JS port via GWT
  • 7. (GWT – Google Web Toolkit) • Open source set of tools • Write JavaScript front-end applications in Java • Used as a front-end by some Java EE solutions – (GWT + ExtJS, GXT)
  • 8. (GWT – Google Web Toolkit) • Advantages – Removes unused code – Compile time checking – Inlines, optimizes – Obfuscates output – Adjusted for browser quirks • Disadvantage: not all Java libraries can be compiled by GWT, in fact it’s very limited!
  • 9. PlayN – platform • Java SE - native • HTML 5 – using GWT • Flash – not really functional any more AFAIK • Android – almost native Java • iOS – using Xamarin framework + Visual Studio – Upcoming: using RoboVM
  • 10. PlayN platforms • All Java code you write should be able to be consumed by GWT compilation and also Android dexer
  • 11. HTML5 • WebGL • Canvas2D • CSS3 • Web Audio API • Most of the PlayN platform implementations try to support hardware acceleration
  • 12. Attribution • A bunch of slide material from Lilli • Used some material from Michael Twohey, member of our project and Team Bad Wolf • Deal-O-Round project (Team Bad Wolf)
  • 13. PlayN API • Keep core small
  • 15. The Game Loop • Implement PlayN.Game public class MyGame implements Game { public void init() { // initialize game. } public void update (float delta) { // update world. } public void paint (float alpha) { // render world. } }
  • 16. Rendering // Each device has different screen parameters // Resize to the available resolution on the current device. graphics().setSize( graphics().screenWidth(), graphics().screenHeight() ); // Keep the same aspect ratio. float sx = graphics().screenWidth() / (float) WIDTH; float sy = graphics().screenHeight() / (float) HEIGHT; // Fit to the available screen without stretching. graphics().rootLayer().setScale(Math.min(sx, sy));
  • 19. Layer types • Layers have distinct sizes and transforms • Used to optimize
  • 20. SurfaceLayer • Traditional rendering paradigm • Render multiple images into a single surface • Clear each frame // Clear the surface. surface.clear(); // Draw an image into the surface. surface.drawImage(myImage, x, y); // Draw a scaled subsection of the source image into the surface. surface.drawImage(image, dx, dy, dw, dh, sx, sy, sw, sh);
  • 22. ImageLayer • Fire and forget image • Don't need to draw in paint() • Render images not in scenegraph • UI, logos, overlays
  • 23. CanvasLayer • Mirrors much of the HTML5 canvas API • Procedural circle, rect, line, point, gradient... • Text rendering • Slow canvas.setFillColor(Color.rgb(100, 255, 0)); canvas.fillCircle(x, y, r); canvas.fillRect(x, y, w, h); canvas.drawImage(myImage, x, y); canvas.drawText("Hello text!", x, y); canvas.drawLine(x0, y0, x1, y1);
  • 24. Layers recap • 3/4 layer types can draw images • SurfaceLayer for standard sprite rendering • GroupLayer for organization • ImageLayer for static images • CanvasLayer for procedural drawing
  • 25. Transforms and surfaces // Like OpenGL push. surface.save(); surface.translate(p.x, p.y); surface.rotate(p.r); surface.scale(p.sx, p.sy); // Draw something at transformed coordinates! // Like OpenGL pop. surface.restore();
  • 26. IO System: Platform Abstractions • Pointer – Most general screen event Works everywhere • Mouse – Left, right, mid buttons & wheel • Touch – Pressure, size, multitouch
  • 27. IO System • Input devices pointer().setListener(new Pointer.Adapter() { public void onPointerStart(Pointer.Event event) { // Handle mouse down event. } // ...Same pattern for onPointerEnd, onPointerDrag }); keyboard().setListener(new Keyboard.Adapter() { public void onKeyDown(Event event) { // Handle key down event. } // ... Same pattern for onKeyUp });
  • 28. Cross platform input • Support touch-based zoom where available import static playn.core.PlayN.platformType; if (platformType().equals(Platform.Type.ANDROID)) { touch().setListener(new Touch.Adapter() { @Override public void onTouchStart(Event[] touches) { // Process touch events into a zoom start position. } @Override public void onTouchMove(Event[] touches) { // Update zoom based on touches. } }); }
  • 29. Asset Management • Abstraction for platform-specific resource fetching public interface AssetManager { Image getImage(String path); Sound getSound(String path); void getText(String path, ResourceCallback callback); boolean isDone(); int getPendingRequestCount(); }
  • 30. Loading Images • Abstraction for platform-specific resource fetching // Ask the Asset Manager to create a new image. Image image = assetManager().getImage("myImage.png"); // Specify an onLoaded callback. image.addCallback(new ResourceCallback() { public void done(Image image) { // handle new image. } } // To draw the image that was loaded, render it to a layer. mySurfaceLayer.surface().drawImage(image, x, y);
  • 31. Asset Watchers • Make sure everything is loaded before you start the game AssetWatcher watcher = new AssetWatcher(new Listener() { public void done() { startGame(); } }); // Add assets to check. watcher.add(image1); watcher.add(image2); // ... // Start the watching now. watcher.start();
  • 32. Sounds • Use PlayN.core.Sound() abstraction • HTML5 version uses Web Audio API via gwt-voices public interface Sound { boolean play(); void stop(); void setLooping(boolean looping); void setVolume(float volume); boolean isPlaying(); } assetManager().getSound("mySound.mp3");
  • 33. Storage • 5MB max due to HTML5 local storage limits • Strings only (for now) /** Abstraction for Storage across platforms. */ public interface Storage { public void setItem(String key, String data); public void removeItem(String key); public String getItem(String key); // Returns true if the Storage data will be persisted across restarts. public boolean isPersisted(); }
  • 35. JSON loading • JSON implementation is platform specific PlayN.assetManager().getText(JSON_FILE, new ResourceCallback() { @Override public void done(String resource) { Json.Object json = PlayN.json().parse(resource); Json.Array myArray = json.getArray("myArray"); int myInt = json.getInt("myInt"); } @Override public void error(Throwable err) { PlayN.log().error("Failed to load: " + err.getMessage()); } });
  • 36. JSON saving Writer writer = PlayN.json().newWriter(); writer.object(); writer.key("myInt"); writer.value(123); writer.key("myArray"); writer.array(); for (String s : arrayOfStringParams) { writer.value(s); } writer.endArray(); writer.endObject(); String output = writer.write();
  • 37. Recap so far • Main game loop • Render efficiently • Handle input • Load assets • Play audio • Save data
  • 38. Extras • Even in-app payment is supported in platform independent API
  • 39. Links • Mike Twohey’s presentation: https://drive.google.com/file/d/0Bx6U- HF_yP7qcWdiRXdCdTQyams/view • Lilli’s presentation: – http://playn-2011.appspot.com/ • Chris Mohritz presentation, good hands-on lab: http://www.slideshare.net/ChrisMohritz/building-crossplatform- games-with-google-playn-14294882 • Where to start: – https://code.google.com/p/playn/wiki/GettingStarted – https://developers.google.com/playn
  • 40. We are not done yet at all • How to draw menus, buttons, texts? – We can draw texts, but what about buttons and widgets? • Answer: Triple Play – https://github.com/threerings/tripleplay – https://github.com/threerings/playn – collection of game-related utility classes that can be used with the PlayN library – Layouting engine – Widget set (buttons, labels, sliders, …) – Formatting
  • 41. What you need • Eclipse IDE with Android plugins • Maven build system • M2E plugin for Eclipse • Extremely easily scaffold a skeleton with a Maven archetype: mvn archetype:generate -DarchetypeGroupId=com.googlecode.playn -DarchetypeArtifactId=playn-archetype -DarchetypeVersion=1.8
  • 42. Showcase: Deal-O-Round • Team Bad Wolf was formed for 59 Days of Code – Csaba Toth, Michael Twohey, Tim Yopp, Vernon Burt • Deal-O-Round is a card game • Uses PlayN framework • https://dealoround.com
  • 43. Showcase: Deal-O-Round • Launched June 17th, 2014 on Google Play • Free, ad supported • Early phase prototype, sketch:
  • 44. Demo • File structure • Implementation details
  • 47. Touch Input • onPointerStart • onPointerDrag • onPointerEnd • Button • Debug coordinates
  • 48. Other • Mp3 music • Spin • Timer • Networking • Android • Scoring poker hands
  • 49. Experiences • PlayN is not as popular as Unity or certain other frameworks, sometimes hard to get help • Having the common denominator has restrictions: either you use the PlayN multi platform APIs, or you have to develop platform specific code – OAuth authentication code, networking – won’t go through GWT compilation phase • Preferable for 2D games • Hopefully RoboVM will cause a new momentum • https://code.google.com/p/playn/w/list
  • 50. Future • http://www.robovm.com/ • Will provide Java support for iOS (and Android) • Two developers started it back in 2013 • Oracle featured them and will back them up • PlayN picks it up too • Will provide a much straight path to iOS port than Xamarin/.NET/Visual Studio • 1.9 PlayN version is under development