KEMBAR78
Game On With NativeScript | PPTX
GAME ON!
WITH
NATIVESCRIPT
J E N L O O P E R | D E V R E L @ T E L E R I K
@ J E N L O O P E R
$ 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
WHAT IS
NATIVESCRIPT?
A RUNTIME FOR BUILDING AND RUNNING
NATIVE IOS, ANDROID, AND (SOON)
WINDOWS PHONE APPS WITH A SINGLE,
JAVASCRIPT CODE BASE
• No cross
compilation
!
=
!
=
• Direct access to
native APIs in JS
!
=
• No DOM
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!
CONTRIBUTE!
(NATIVESCRIPT.ORG/CONTRIBUTE)
NATIVESCRIPT ANDROID EXAMPLE
Output:
NATIVESCRIPT IOS EXAMPLE
HOW DOES THIS WORK?
NATIVESCRIPT AND JS VMS
NativeScript runs JavaScript on a JavaScript
VM
•JavaScriptCore on iOS
•V8 on Android
• Runs on JavaScriptCore
• Runs on V8
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).
NATIVESCRIPT FILE MODULE
NATIVESCRIPT HTTP MODULE
COMMUNITY MODULES
NEW! PLUGIN MARKETPLACE!
BUT HOW DO I TURN THIS INTO AN APP?
2 WAYS TO USE NATIVESCRIPT
1)
2)
• 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
•In-Browser Client
•Visual Studio Extension
•Sublime Text Package
•Command-Line Interface
TELERIK APPBUILDER IDE OPTIONS
PRICING
https://www.telerik.com/purchase/appbuilder
NATIVESCRIPT CLI
•Free and open source
•https://github.com/nativescript/nativescri
pt-cli
NATIVESCRIPT CLI REQUIREMENTS
https://github.com/nativescript/nativescript-
cli#system-requirements
• Xcode, Xcode CLI tools, iOS SDK
• JDK, Apache Ant, Android SDK
LEARN MORE!
NativeScript Getting Started Guide:
http://docs.nativescript.org/getting-started
STARTING A NEW PROJECT
RUNNING ON IOS
RUNNING ON ANDROID
DEVELOPER HELPS!
1. Livesync!
2. Sublime Text Settings to build
3. Deploy to device
Cmd + B
APP STRUCTURE
APP.JS
PAGES
• XML markup structure
• Elements (e.g. <Page>, <Label>) are NativeScript
modules
CUSTOM XML COMPONENTS
http://docs.nativescript.org/ui-with-xml#custom-components
DATA BINDING
DATA BINDING IMPROVED
CSS
http://docs.nativescript.org/styling#supported-properties
CSS
LET’S BUILD SOMETHING!
A GAME INSPIRED BY…
• Show picture of llama or duck
• Very quickly timeout
• Show high scores
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)
PRESENTING…
THISORTHAT:
A GAME OF WORDS AND TAGS
O P E N S O U R C E !
Android
download
https://github.co
m/jlooper/thisort
hat-app
iOS download
THISORTHAT: CODE WALKTHROUGH
• Basic structure
• API integration
• Authentication
• View models
• Shared code
• Animation
• Platform-specific code
• Cocoapods and Toast plugin
• Npm module – email-
validator
THISORTHAT:
BASIC CODE STRUCTURE
• Quick code structure rundown
THISORTHAT: API INTEGRATION
• Shared/config.js
• Data persistence
THISORTHAT: AUTHENTICATION
• Login
• Password
• Register
THISORTHAT: VIEW MODELS
• Shared/view-models/game-view-model.js
• Shared/view-models/user-view-model.js
THISORTHAT: SHARED CODE
• Shared/navigation.js
• Shared/utils/form-util.js
THISORTHAT: ANIMATION
• Nativescript’s built-in animation library
THISORTHAT: IMAGES
• Content-scaled images
• Non-content-scaled images
THISORTHAT: PLATFORM-SPECIFIC
CODE
• CSS
• Utils/action-bar-util.js
• Utils/form-util.js
• Inline: login/login.js
THISORTHAT: COCOAPODS AND NPM
MODULES
• fancyAlert (YCTutorialBox)
• email-validator (generic npm module)
• Nativescript-toast (nativescript-based npm modules)
LET’S PLAY!
H M U !
Jen Looper
@jenlooper
jen.looper@telerik.co
m
Learn more about
NativeScript at the Telerik
booth and at
nativescript.org

Game On With NativeScript

Editor's Notes

  • #11 this JavaScript code instantiates a Java android.text.format.Time() object, calls its set() method, then logs the return value of its format() method, which is the string "01/01/15".
  • #12 This JavaScript code instantiates an Objective-C UIAlertView class, sets its message property, and then calls its addButtonWithTitle() and show() methods. When you run a NativeScript iOS app with this code you'll see the alert "hello world!"
  • #13 Use native classes which you can find in the native documentation to craft your nativescript code
  • #15 NativeScript is a runtime that leverages platform-specific JavaScript engines (javascriptcore and V8)
  • #21 this filesystem module allows you to pass through a path that you define as a parameter. On Android a new file will be created at that location, and on iOS we instantiate the NSFileManager as the default manager and tell it to create the file on that path. All with one require and one line of javascript.
  • #22 the http module allows you to make http calls and return json results.
  • #30 free 30 day trial
  • #37 Do this live – show livesync Show sublime build script Preferences > Browse Packages > User/nativescript.sublime-build
  • #42 Use the load function to bind data to an xml element
  • #43 Or use the observable module to take care of it – mvvm people will feel comfortable.
  • #47 Played by pewdiepie and became popular
  • #48 http://clarifai.com/#demo