Skip to content

Commit

Permalink
a scene can now be loaded with options
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeen committed Oct 19, 2012
1 parent 4f8199f commit 57d665d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
17 changes: 15 additions & 2 deletions app/models/scene.js
Expand Up @@ -6,17 +6,30 @@ define([

var Scene = Backbone.Model.extend({
defaults: {
optionsBuffer: {},
init: function() {},
uninit: function() {}
},
initialize: function() {
return Crafty.scene(this.get("name"), this.get("init"), this.get("uninit"));

var init = this.get("init");
var scene = this;

return Crafty.scene(this.get("name"), function() {
init(scene.optionsBuffer);
}, this.get("uninit"));

},
load: function() {
load: function(options) {

this.optionsBuffer = options || {};

var sceneName = this.get("name");
assets.loadByScene(sceneName, function() {
Crafty.scene(sceneName);
this.optionsBuffer = {};
});

}
});

Expand Down
2 changes: 1 addition & 1 deletion app/views/levels/show.js
Expand Up @@ -10,7 +10,7 @@ define([
el: $("#wrapper"),
render: function(id) {

scenes.findByName("level").load();
scenes.findByName("level").load({level: id});

this.$el.html(_.template(_show));
$("#ig_menu button").click(function() {
Expand Down
4 changes: 2 additions & 2 deletions game/scenes/level.js
Expand Up @@ -5,8 +5,8 @@ define(function(require) {

return {
name: "level",
init: function() {
console.log("Level loaded");
init: function(options) {
console.log("Level loaded", options);
player.create();
}
};
Expand Down

0 comments on commit 57d665d

Please sign in to comment.