Created
February 5, 2013 11:23
-
-
Save ahomu/4713842 to your computer and use it in GitHub Desktop.
CreateJSのプリロードと適用周りをむりやりModelっぽくしてみたりウーン...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* CreatejsModel | |
* | |
* 大雑把にこんな??? | |
* var scene01 = new CreatejsModel({animationName: 'scene01'}); | |
* scene01.apply($('canvas#sceneStage')); | |
*/ | |
define(['backbone', 'anim', 'createjs'], function(Backbone, Anim, createjs) { | |
return Backbone.model.extend({ | |
url: 'resource-manifests.json', | |
preloaded: false, | |
options: { | |
animationName: '__default__' | |
}, | |
initialize:function () { | |
window.images = window.images || {}; | |
_.bindAll(this); | |
this.fetch({ | |
success: this.preload | |
}); | |
}, | |
ready: function(callback) { | |
if (this.preloaded) { | |
callback(); | |
} else { | |
this.on('preloaded', callback); | |
} | |
}, | |
preload: function() { | |
var loader = new createjs.PreloadJS(false); | |
loader.onFileLoad = this._handleFileLoad; | |
loader.onComplete = this._handleComplete; | |
loader.loadManifest(this.get('manifests')); | |
}, | |
_handleFileLoad: function(o) { | |
if (o.type === 'image') { images[o.id] = o.result; } | |
}, | |
_handleComplete: function() { | |
this.preloaded = true; | |
this.trigger('preloaded'); | |
this.off('preloaded'); | |
}, | |
apply: function($canvases) { | |
var that = this; | |
// ready? | |
this.ready(function() { | |
$canvases.each(function() { | |
var exportRoot, stage, mask, canvas; | |
canvas = this; | |
exportRoot = new Anim[that.options.animationName](); | |
stage = new createjs.Stage(canvas); | |
stage.addChild(exportRoot); | |
stage.update(); | |
createjs.Ticker.addListener(stage); | |
createjs.Ticker.setFPS(30); | |
}); | |
}); | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifests": [ | |
{"src":"img/aaa.png", "id":"aaa", "type":"image"}, | |
{"src":"img/bbb.png", "id":"bbb", "type":"image"}, | |
{"src":"img/ccc.png", "id":"ccc", "type":"image"}, | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment