Best Practices For developing a web game in modern browsers Colt - - PowerPoint PPT Presentation

best practices
SMART_READER_LITE
LIVE PREVIEW

Best Practices For developing a web game in modern browsers Colt - - PowerPoint PPT Presentation

Best Practices For developing a web game in modern browsers Colt "MainRoach" McAnlis 3.05.2012 The call me "web game" Content Server Database Gameplay Server Google App Engine Google Analytics Social Graph Client


slide-1
SLIDE 1

Best Practices

For developing a web game in modern browsers

Colt "MainRoach" McAnlis 3.05.2012

slide-2
SLIDE 2

The call me "web game"

Client Display Scripting Content Server Database Gameplay Server Social Graph Monetize Google App Engine Google Wallet Google Analytics Chrome Web Store

slide-3
SLIDE 3

The Rundown

Content Distrib Database Login & Auth Localization Rendering Web & Platform User Metrics Monetization

slide-4
SLIDE 4

Serving content

slide-5
SLIDE 5

Serving & Caching

SERVER

HTML JS JPG JSON ZIP

CLIENT

Chrome Cache Persistent File Store

page load / resource load / XHttpRequest FileStore API

OGG

slide-6
SLIDE 6

Serving & Scaling

SERVER XHR / load CLIENTS x 1 mill

HTML JS JPG JSON ZIP OGG

slide-7
SLIDE 7

Serving & Scaling

SERVERS CLIENTS x 1 mill

slide-8
SLIDE 8

Loose Files

CLIENT

Chrome Cache

slide-9
SLIDE 9

Archiving Wins

CLIENT

Persistent File Store

FileStore API ZIP file

File System

slide-10
SLIDE 10

Segmenting & updating

CLIENT

Persistent File Store

ZIP FILES

slide-11
SLIDE 11

GAE Data storage

Store segmented binary archives here

Can carefully control serving costs <32mb served HTML style >=32mb served from blobstore API Set Browser Cache expiration date - link Lets the browse know how long an object is valid Default is 10 min!

slide-12
SLIDE 12

Public Service Announcement

Do Not use the 'existence' of data to represent 'user has bought this'

slide-13
SLIDE 13

Database

slide-14
SLIDE 14

App Engine

Available database using GQL query language Auto-scales to handle demand Cost based upon performance

slide-15
SLIDE 15

App Engine

Set the cache-time for the GET responses

Date now = new Date(); long age = 86400L; resp.setDateHeader("Date", now.getTime()); resp.setHeader("Cache-Control", "public, s-maxage=" + age);

slide-16
SLIDE 16

App Engine - Memcache

Use Memcache - link

Intended for fast access to cached results of queries

def get_data(): data = memcache.get("key") if data is not None: return data else: data = self.query_for_data() memcache.add("key", data, 60) return data

slide-17
SLIDE 17

Sync data between clients

Polling

Each client asks the server continuously

Channel API - link

server tells client when data is ready Can only communicate with javascript!

slide-18
SLIDE 18

Login & Auth

slide-19
SLIDE 19

Mo' logins, Mo' problems

slide-20
SLIDE 20

Mo' logins, less' problems

slide-21
SLIDE 21

Keep your keys

Auth Key Game User Key

slide-22
SLIDE 22

Two step security

More - link.

slide-23
SLIDE 23

Localization

slide-24
SLIDE 24

Localizing matters!

Big markets internationally Languages don't act the same

Languages read in different directions It changes your UI layout! Long words / phrases

slide-25
SLIDE 25

Detecting language

Use navigator.language in JS

browser settings don't change this though

Browser settings affect Http-Accept header Fetch via polling a server function

slide-26
SLIDE 26

Fetch Language

var language; $.ajax({ url: "http://ajaxhttpheaders.appspot.com", dataType: 'jsonp', success: function(headers) { language = headers['Accept-Language']; nowDoSomethingWithIt(language); } }); More - link.

slide-27
SLIDE 27

Get your translate on

slide-28
SLIDE 28

Translate API

https://www.googleapis.com/language/translate/v2/detect?key=INSERT-YOUR-KEY&q=google+translate+is+fast

slide-29
SLIDE 29

Tooling!

slide-30
SLIDE 30

Display & Rendering

slide-31
SLIDE 31

Using GPU on the web

GPU Drivers not always safe... Black-listed drivers

Detect and respond early!

slide-32
SLIDE 32

Blacklisted driver test

//has blacklisted hardware / feature sets?

function textureSizeTest(size) { var canvas = document.createElement('canvas'); var gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl'); if (gl) { return gl.getParameter(gl.MAX_TEXTURE_SIZE) >= size; }

slide-33
SLIDE 33

Sandbox Rendering

Chrome

Render Process

RPC Buffer

...

slide-34
SLIDE 34

Draw obj

Render Stalls

Draw obj Update VB Swap Buffers glFinish Draw obj Update VB

...

RPC Buffer

Draw obj

...

FLUSH

...

slide-35
SLIDE 35

Render Stalls

Draw obj Update VB

...

RPC Buffer

Draw obj F L U S H

...

glFlush() Draw obj F L U S H glFlush()

slide-36
SLIDE 36

Canvas rendering

GPU accelerated canvas rendering

Chrome 17

Hands-free usage

Setup behind the scenes User can toggle flag

slide-37
SLIDE 37

Platform env

slide-38
SLIDE 38

Lost attention

Users will tab away from your page. Detect this - visibilitychange event Respond accordingly

pause game, reduce volume setInterval will slow down to 1000ms RequestAnimationFrame will stop completely

slide-39
SLIDE 39

Bugs in the wild

Detect this window.onerror, v8-Error.captureStackTrace Respond accordingly Gather -

game specific - game state, OS, player ID, etc env - window.performance / chrome.tabs.captureVisibleTab

Upload -

jsErrLog / jdrop

slide-40
SLIDE 40

Make sure your error reporting is stable Display errors to user

be friendly, avoid technical language

Respect your users' privacy

Ensure user knows what's being reported Offer ability to opt-out

Lots 'o bugs

slide-41
SLIDE 41

Closure compiler - link plovr - link HTML5 boiler plate - link

Minimize & obfuscate

slide-42
SLIDE 42

User Metrics

slide-43
SLIDE 43

Know thine players

Use Google Analytics! Can kick off custom events too! Custom game events

finish lvl 2, finish a game, chatted, join a group, assault a chicken...

slide-44
SLIDE 44

The high points

Use GA

Whats your daily, weekly, monthly averages? % of players come from what site # of players that click 'buy' # of players that complete a 'buy'

Use own server

track in-game events # crashes, bugs, specific errors

slide-45
SLIDE 45

AB testing

Is there a secret sauce to a better game?

Disconnect between devs & users

Issue separate builds to 50% of your users

Track desired outcome somehow

Make changes to optimize your outcome

Might be multiple split by region / user

slide-46
SLIDE 46

Monetization

slide-47
SLIDE 47

Guide the user

Monetization is a dark art.

game specific, platform specific etc

Hold the user's hand

How do they purchase Why should they purchase

slide-48
SLIDE 48

Premium vs freemium

slide-49
SLIDE 49

For sale

slide-50
SLIDE 50

Virtual currency

Have a multiple currency system

Premium currency from IAP Grind currency from gameplay Enable trading between currencies

Enable Instant gratification

slide-51
SLIDE 51

Simplified purchase flow

Leverage In-App Payment APIs

rather than directing user to a pay-site

Great features

Access to millions of existing CCs Powerful fraud engine Plug and play purchase flow Pay in a few clicks

Google Wallet

slide-52
SLIDE 52

Take outs

slide-53
SLIDE 53

Takeouts

Bundle assets into segmented archives Set proper cache times for data & query fetches Use a single-login service for your users Localize your content properly Detect GPU blacklist and performance changes

slide-54
SLIDE 54

Takeouts

Detect and fetch bugs in the wild Detect and respond to user focus loss Track as much user data as possible Choose monetization metric that fits your game Focus on Consumable and durable goods Focus on in-app API for purcahses.

slide-55
SLIDE 55

Takeouts

Lots of work to develop a game

That has nothing to do with your game

Leverage Google services

Free to get started

slide-56
SLIDE 56

Thanks!

colton@google.com

Contributors: Chrome Developer Relations Special Thanks : Peng Ying, Fred Sauer

+Colt McAnlis @duhroach mainroach.blogspot.com

slide-57
SLIDE 57

default text color Charts, Strokes supported text Google Additional 1