game on! with nativescript

62
GAME ON! WITH NATIVESCRIPT JEN LOOPER | DEVREL @TELERIK @JENLOOPER

Upload: dokiet

Post on 13-Feb-2017

231 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Game on! With Nativescript

GAME ON!WITH

NATIVESCRIPTJ E N LO O P E R | D E V R E L @ T E L E R I K

@ J E N LO O P E R

Page 2: Game on! With Nativescript

$ WHOAMI• Ph.D. … in Medieval French (13th

century prose romance FTW)• Retrained!• Worked in startup, nonprofit, big

corporate 14 yrs+• A lot of side projects –

ladeezfirstmedia.com• Now DevRel@Telerik

Page 3: Game on! With Nativescript

WHAT IS NATIVESCRIPT?

Page 4: Game on! With Nativescript

A RUNTIME FOR BUILDING AND RUNNING NATIVE IOS, ANDROID, AND (SOON) WINDOWS PHONE APPS WITH A SINGLE, JAVASCRIPT CODE BASE

Page 5: Game on! With Nativescript
Page 6: Game on! With Nativescript

•No cross compilation

!=

!=

•Direct access to native APIs in JS

!=

•No DOM

Page 7: Game on! With Nativescript

WHY NATIVESCRIPT?• Skills reuse

• Standards-based JavaScript, CSS, optionally TypeScript• Code reuse

• npm modules, 3rd-party iOS and Android libraries• Easily use native APIs

• No wrappers to access native APIs• Use native UI elements

• Open source!

Page 8: Game on! With Nativescript

CONTRIBUTE! (NATIVESCRIPT.ORG/CONTRIBUTE)

Page 9: Game on! With Nativescript
Page 10: Game on! With Nativescript

NATIVESCRIPT ANDROID EXAMPLE

Output:

Page 11: Game on! With Nativescript

NATIVESCRIPT IOS EXAMPLE

Page 12: Game on! With Nativescript
Page 13: Game on! With Nativescript

HOW DOES THIS WORK?

Page 14: Game on! With Nativescript

NATIVESCRIPT AND JS VMS

NativeScript runs JavaScript on a JavaScript VM

• JavaScriptCore on iOS•V8 on Android

Page 15: Game on! With Nativescript
Page 16: Game on! With Nativescript

•Runs on JavaScriptCore

•Runs on V8

Page 17: Game on! With Nativescript
Page 18: Game on! With Nativescript
Page 19: Game on! With Nativescript

NATIVESCRIPT MODULES• NativeScript-provided modules that provide cross-platform functionality.

• There are dozens of them and they’re easy to write yourself.

• NativeScript modules follow Node module’s conventions (CommonJS).

Page 20: Game on! With Nativescript

NATIVESCRIPT FILE MODULE

Page 21: Game on! With Nativescript

NATIVESCRIPT HTTP MODULE

Page 22: Game on! With Nativescript

COMMUNITY MODULES

Page 23: Game on! With Nativescript

NEW! PLUGIN MARKETPLACE!

Page 24: Game on! With Nativescript

BUT HOW DO I TURN THIS INTO AN APP?

Page 25: Game on! With Nativescript

2 WAYS TO USE NATIVESCRIPT

1)

2)

Page 26: Game on! With Nativescript

• Backend-as-a-service– Push notifications, cloud data, file storage, etc

• Analytics• AppBuilder

– Cloud builds (build iOS apps on Windows, Windows Phone apps on a Mac)

– NativeScript debugging and tooling• Screen Builder (app scaffolding)• And more!

http://telerik.com/platform

Page 27: Game on! With Nativescript

• In-Browser Client•Visual Studio Extension•Sublime Text Package•Command-Line Interface

TELERIK APPBUILDER IDE OPTIONS

Page 28: Game on! With Nativescript
Page 29: Game on! With Nativescript

PRICINGhttps://www.telerik.com/purchase/appbuilder

Page 30: Game on! With Nativescript

NATIVESCRIPT CLI•Free and open source•https://github.com/nativescript/nativescript-cli

Page 31: Game on! With Nativescript

NATIVESCRIPT CLI REQUIREMENTShttps://github.com/nativescript/nativescript-cli#system-requirements

• Xcode, Xcode CLI tools, iOS SDK

• JDK, Apache Ant, Android SDK

Page 32: Game on! With Nativescript

LEARN MORE!NativeScript Getting Started Guide: http://docs.nativescript.org/getting-started

Page 33: Game on! With Nativescript

STARTING A NEW PROJECT

Page 34: Game on! With Nativescript

RUNNING ON IOS

Page 35: Game on! With Nativescript

RUNNING ON ANDROID

Page 36: Game on! With Nativescript

DEVELOPER HELPS!1. Livesync!

2. Sublime Text Settings to build

3. Deploy to device

Cmd + B

Page 37: Game on! With Nativescript

APP STRUCTURE

Page 38: Game on! With Nativescript

APP.JS

Page 39: Game on! With Nativescript

PAGES• XML markup structure• Elements (e.g. <Page>, <Label>) are NativeScript modules

Page 40: Game on! With Nativescript

CUSTOM XML COMPONENTS

http://docs.nativescript.org/ui-with-xml#custom-components

Page 41: Game on! With Nativescript

DATA BINDING

Page 42: Game on! With Nativescript

DATA BINDING IMPROVED

Page 43: Game on! With Nativescript

CSS

http://docs.nativescript.org/styling#supported-properties

Page 44: Game on! With Nativescript

CSS

Page 45: Game on! With Nativescript

LET’S BUILD SOMETHING!

Page 46: Game on! With Nativescript

A GAME INSPIRED BY…

• Show picture of llama or duck

• Very quickly timeout• Show high scores

Page 47: Game on! With Nativescript

LET’S USE THE CLARIFAI API TOO!A souped-up Llama vs. Duck with

educational ++• Pick 2 images• Query Clarifai to get 2 sets of tags• Create game loop to let user choose This or That• Localize the tags using Clarifai’s translations (20

languages!) (Settings area)• Timeout after 5 seconds• Show high scores (Telerik Platform integration)• Show my scores (also Telerik Platform)

Page 48: Game on! With Nativescript

PRESENTING…

Page 49: Game on! With Nativescript

THISORTHAT: A GAME OF WORDS AND TAGS

Page 50: Game on! With Nativescript

OPEN SOURCE!

Android download

https://github.com/jlooper/thisorthat-app

iOS download

Page 51: Game on! With Nativescript

THISORTHAT: CODE WALKTHROUGH• Basic structure

• API integration• Authentication• View models• Shared code• Animation• Platform-specific code• Cocoapods and Toast

plugin• Npm module – email-

validator

Page 52: Game on! With Nativescript

THISORTHAT: BASIC CODE STRUCTURE• Quick code structure rundown

Page 53: Game on! With Nativescript

THISORTHAT: API INTEGRATION• Shared/config.js• Data persistence

Page 54: Game on! With Nativescript

THISORTHAT: AUTHENTICATION• Login• Password• Register

Page 55: Game on! With Nativescript

THISORTHAT: VIEW MODELS

• Shared/view-models/game-view-model.js• Shared/view-models/user-view-model.js

Page 56: Game on! With Nativescript

THISORTHAT: SHARED CODE

• Shared/navigation.js• Shared/utils/form-util.js

Page 57: Game on! With Nativescript

THISORTHAT: ANIMATION

• Nativescript’s built-in animation library

Page 58: Game on! With Nativescript

THISORTHAT: IMAGES

• Content-scaled images• Non-content-scaled images

Page 59: Game on! With Nativescript

THISORTHAT: PLATFORM-SPECIFIC CODE• CSS• Utils/action-bar-util.js• Utils/form-util.js

• Inline: login/login.js

Page 60: Game on! With Nativescript

THISORTHAT: COCOAPODS AND NPM MODULES• fancyAlert (YCTutorialBox)• email-validator (generic npm module)• Nativescript-toast (nativescript-based npm modules)

Page 61: Game on! With Nativescript

LET’S PLAY!

Page 62: Game on! With Nativescript

HMU!

Jen [email protected]@telerik.com

Learn more about NativeScript at the Telerik booth and at nativescript.org