62
Building games Matt Gamache-Asselin @mattieuga Parse with Wednesday, May 1, 13

Building AnyYolk with the Parse JavaScript SDK

  • Upload
    parseit

  • View
    1.558

  • Download
    3

Embed Size (px)

DESCRIPTION

This webcast explored how to create the game AnyYolk based on the following concepts: How to create web apps with Backbone.js Best practices of Backbone.js How the Parse SDK works with Backbone.js Live example of adding a highscore to a Backbone.js game How you can use Cloud Code to add server-side functionality to your Parse app

Citation preview

Page 1: Building AnyYolk with the Parse JavaScript SDK

Building games

Matt Gamache-Asselin @mattieuga

Parsewith

Wednesday, May 1, 13

Page 2: Building AnyYolk with the Parse JavaScript SDK

Wednesday, May 1, 13

Page 3: Building AnyYolk with the Parse JavaScript SDK

Database

Wednesday, May 1, 13

Page 4: Building AnyYolk with the Parse JavaScript SDK

Database Server+

+ users+ security

Wednesday, May 1, 13

Page 5: Building AnyYolk with the Parse JavaScript SDK

Database REST API

ZZZ

Server+

+ users+ security

+

Wednesday, May 1, 13

Page 6: Building AnyYolk with the Parse JavaScript SDK

Database REST API

ZZZ

Server+

+ users+ security

Networking

+

+

Wednesday, May 1, 13

Page 7: Building AnyYolk with the Parse JavaScript SDK

Database REST API

ZZZ

Server

+

+

+ users+ security

Networking The fun stu!!

+

+

Wednesday, May 1, 13

Page 8: Building AnyYolk with the Parse JavaScript SDK

Database REST API

ZZZ

Server

+

+

+ users+ security

Networking The fun stu!!

+

+

Wednesday, May 1, 13

Page 9: Building AnyYolk with the Parse JavaScript SDK

Database REST API

ZZZ

Server

+

+

+ users+ security

Networking The fun stu!!

+

+

Wednesday, May 1, 13

Page 10: Building AnyYolk with the Parse JavaScript SDK

Database REST API

ZZZ

Server

+

+

+ users+ security

Networking The fun stu!!

+

+

Wednesday, May 1, 13

Page 11: Building AnyYolk with the Parse JavaScript SDK

iOS Android OS X WP8 Win 8 .NET Cloud Code REST

JavaScript

Wednesday, May 1, 13

Page 12: Building AnyYolk with the Parse JavaScript SDK

Giving your code a BACKBONE.JS

Wednesday, May 1, 13

Page 13: Building AnyYolk with the Parse JavaScript SDK

ScoreViewGameView Pro!leView

Wednesday, May 1, 13

Page 14: Building AnyYolk with the Parse JavaScript SDK

ScoreViewGameView Pro!leView

Wednesday, May 1, 13

Page 15: Building AnyYolk with the Parse JavaScript SDK

Backbone.Event

Wednesday, May 1, 13

Page 16: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Wednesday, May 1, 13

Page 17: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

Wednesday, May 1, 13

Page 18: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

Backbone.View

Backbone.View

Wednesday, May 1, 13

Page 19: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

var ScoreModel = Backbone.Model.extend({

});

Wednesday, May 1, 13

Page 20: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

var ScoreModel = Backbone.Model.extend({

defaults: { score: 0, level: 1, mult: 1 },

});

Wednesday, May 1, 13

Page 21: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

var ScoreModel = Backbone.Model.extend({

defaults: { score: 0, level: 1, mult: 1 }, incrementScore: function() { this.set(“score”, this.get(“score”) + this.get(“mult”); }});

Wednesday, May 1, 13

Page 22: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

var scoreModel = new ScoreModel();

scoreModel.incrementScore();

Wednesday, May 1, 13

Page 23: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

change

change:scoreScoreModel

var scoreModel = new ScoreModel();

scoreModel.incrementScore();

Wednesday, May 1, 13

Page 24: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

var ScoreView = Backbone.View.extend({

});

var scoreView = new ScoreView({ model: scoreModel });

Wednesday, May 1, 13

Page 25: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

var ScoreView = Backbone.View.extend({

render: function() { this.$el.html(“<p>” + this.model.get(“score”) + “</p>”); $(“#game .score”).html(this.$el); return this; }

});

var scoreView = new ScoreView({ model: scoreModel });

Wednesday, May 1, 13

Page 26: Building AnyYolk with the Parse JavaScript SDK

Backbone.ModelBackbone.Event

Backbone.View

var ScoreView = Backbone.View.extend({

initialize: function() { this.model.on(“change:score”, this.render); },

render: function() { this.$el.html(“<p>” + this.model.get(“score”) + “</p>”); $(“#game .score”).html(this.$el); return this; }

});

var scoreView = new ScoreView({ model: scoreModel });

Wednesday, May 1, 13

Page 27: Building AnyYolk with the Parse JavaScript SDK

ScoreModelchange:score

ScoreView

Wednesday, May 1, 13

Page 28: Building AnyYolk with the Parse JavaScript SDK

ScoreModelchange:score

ScoreView

Backbone.Collection Backbone.Router

Wednesday, May 1, 13

Page 29: Building AnyYolk with the Parse JavaScript SDK

Wednesday, May 1, 13

Page 30: Building AnyYolk with the Parse JavaScript SDK

GameState

GameScene MenuScene HighScoreScene GameOverScene

Events

EggModel

EggView

Wednesday, May 1, 13

Page 31: Building AnyYolk with the Parse JavaScript SDK

ParseIt’s all about the server

Wednesday, May 1, 13

Page 32: Building AnyYolk with the Parse JavaScript SDK

Backbone.Model

Backbone.View

Backbone.Collection

Backbone.Router

Wednesday, May 1, 13

Page 33: Building AnyYolk with the Parse JavaScript SDK

Parse.Object

Backbone.View

Parse.Collection

Backbone.Router

Wednesday, May 1, 13

Page 34: Building AnyYolk with the Parse JavaScript SDK

Parse.Object

Backbone.View

Parse.Collection

Backbone.Router

Parse

Wednesday, May 1, 13

Page 35: Building AnyYolk with the Parse JavaScript SDK

Parse.Object

Backbone.View

Parse.Collection

Backbone.Router

Parse.User

Parse.Query

Parse.ACL

Parse.Cloud

Parse.Roles

Parse.Push

Parse.FacebookUtils

Parse.Promise

Parse

Wednesday, May 1, 13

Page 36: Building AnyYolk with the Parse JavaScript SDK

USERSThe in your app

Wednesday, May 1, 13

Page 37: Building AnyYolk with the Parse JavaScript SDK

var user = new Parse.User();

user.set("username", "Matt");

user.set("password", "html5r0cks");

user.signUp({

success: function(user) {

console.log("User sign up!");

},

error: function(user, error) {

console.log("Uh oh :( ");

}

});

Wednesday, May 1, 13

Page 38: Building AnyYolk with the Parse JavaScript SDK

var user = new Parse.User();

user.set("username", "Matt");

user.set("password", "html5r0cks");

user.signUp({

success: function(user) {

console.log("User sign up!");

},

error: function(user, error) {

console.log("Uh oh :( ");

}

});

Wednesday, May 1, 13

Page 39: Building AnyYolk with the Parse JavaScript SDK

Parse.User.LogIn("Matt", "html5r0cks", {

success: function(user) {

console.log("User sign up!");

},

error: function(user, error) {

console.log("Uh oh :( ");

}

});

Wednesday, May 1, 13

Page 40: Building AnyYolk with the Parse JavaScript SDK

Parse.User.LogIn("Matt", "html5r0cks", {

success: function(user) {

console.log("User sign up!");

},

error: function(user, error) {

console.log("Uh oh :( ");

}

});

var user = Parse.User.current();

Wednesday, May 1, 13

Page 41: Building AnyYolk with the Parse JavaScript SDK

Parse.FacebookUtils.LogIn({

success: function(user) {

console.log("User sign up!");

},

error: function(user, error) {

console.log("Uh oh :( ");

}

});

Wednesday, May 1, 13

Page 42: Building AnyYolk with the Parse JavaScript SDK

Parse.FacebookUtils.LogIn({

success: function(user) {

console.log("User sign up!");

},

error: function(user, error) {

console.log("Uh oh :( ");

}

});

var user = Parse.User.current();

Wednesday, May 1, 13

Page 43: Building AnyYolk with the Parse JavaScript SDK

Parse.FacebookUtils.LogIn({

success: function(user) {

console.log("User sign up!");

},

error: function(user, error) {

console.log("Uh oh :( ");

}

});

var user = Parse.User.current();

Wednesday, May 1, 13

Page 44: Building AnyYolk with the Parse JavaScript SDK

DATASaving stu" in the

Wednesday, May 1, 13

Page 45: Building AnyYolk with the Parse JavaScript SDK

var score = new Parse.Object("HighScore");

score.set("score", 13);

score.set("player", Parse.User.current());

score.save({

success: function(object) {

console.log("object saved!");

},

error: function(error) {

console.log("Uh oh :( ");

}

});

Wednesday, May 1, 13

Page 46: Building AnyYolk with the Parse JavaScript SDK

var score = new Parse.Object("HighScore");

score.set("score", 13);

score.set("player", Parse.User.current());

score.save({

success: function(object) {

console.log("object saved!");

},

error: function(error) {

console.log("Uh oh :( ");

}

});

Wednesday, May 1, 13

Page 47: Building AnyYolk with the Parse JavaScript SDK

var user = Parse.User.current();

user.set("displayName", nameValue);

user.save({

success: function(user) {

console.log("user saved!");

},

error: function(error) {

console.log("Uh oh :( ");

}

});

Wednesday, May 1, 13

Page 48: Building AnyYolk with the Parse JavaScript SDK

QUERIESGetting stu" from the

Wednesday, May 1, 13

Page 49: Building AnyYolk with the Parse JavaScript SDK

var query = new Parse.Query("HighScore");

query.greaterThan("score", 10);

query.equalTo("player", Parse.User.current());

query.find({

success: function(highScores) {

console.log("My scores over 10" + highScores);

},

error: function(user, error) {

console.log("Uh oh :( ");

}

});

query.descending("score");

Wednesday, May 1, 13

Page 50: Building AnyYolk with the Parse JavaScript SDK

GameState

GameScene MenuScene HighScoreScene GameOverScene

Events

EggModel

EggView

Wednesday, May 1, 13

Page 51: Building AnyYolk with the Parse JavaScript SDK

GameState

GameScene MenuScene HighScoreScene GameOverScene

Events

EggModel

EggView

HighScoreCollection

Parse

Parse.User

Wednesday, May 1, 13

Page 52: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

It’s code in the

Wednesday, May 1, 13

Page 53: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

It’s JavaScript in the Cloud

Wednesday, May 1, 13

Page 54: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

Parse.Cloud.define("averageLikes", function(request, response) { ...});

Parse.Cloud.beforeSave("Post", function(request, response) { ...});

Parse.Cloud.afterSave("Post", function(request, response) { ...});

Wednesday, May 1, 13

Page 55: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

Wednesday, May 1, 13

Page 56: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

Parse.Cloud.httpRequest({   url: 'http://www.parse.com/',   success: function(httpResponse) {     console.log(httpResponse.text);   },   error: function(httpResponse) {     console.error(httpResponse.status);   }});

Wednesday, May 1, 13

Page 57: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

var Mailgun = require('mailgun');Mailgun.initialize('myDomainName', 'myAPIKey');

Parse.Cloud.define("inviteFriends", function(request, response) { var friendEmails = request.params.friends; var userName = Parse.User.current().get(“displayName”);

Mailgun.sendEmail({ to: friendsEmails, from: [email protected], subject: userName + “ invited you to play AnyYolk!”, html: “Try out <a href=‘http://anyyolk.com’>AnyYolk</a> ” + “and compete against ” + userName + “!” }).then(function() { response.success(“Emails sent”); });});

Wednesday, May 1, 13

Page 58: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

Backbone.js

Parse SDK

Wednesday, May 1, 13

Page 59: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

Backbone.js

Cloud Code

Parse

Parse SDK

ClientServer

Wednesday, May 1, 13

Page 60: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

Angular.js

Cloud Code

Parse

Parse SDK

ClientServer

Wednesday, May 1, 13

Page 61: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

Ember.js

Cloud Code

Parse

Parse SDK

ClientServer

Wednesday, May 1, 13

Page 62: Building AnyYolk with the Parse JavaScript SDK

100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001100010101010100010110001100111000100110010100111100011100101011100011100010101010110100010101001010101010101010111100101001101101101010110010010001001101010101011101011011000010010010101010111001

Building games

Matt Gamache-Asselin @mattieuga

Parsewithhttps://github.com/parseplatform/anyyolk

www.anyyolk.com

Wednesday, May 1, 13