OSDN Git Service

delete "/ 20" for TWIPS
[flapp/flapp.git] / main.js
1 (function(global) {
2     var Flapp = function(url, canvas_id) {
3         console.debug("Flapp("+url+","+canvas_id+")");
4         this.url = url;
5         this.canvas_id = canvas_id;
6         this.canvas = document.getElementById(canvas_id);
7         global.flapp = this; // debug
8         this.header = null
9 //      this.frameTick = 1000 / 10; // default 0.1[sec]
10         this.frameTick = 1000; // default
11     };
12     Flapp.prototype = {
13         play: function() {
14             console.debug("Flapp.prototype.play");
15             var flapp = this;
16             var loader = new FlappLoader(flapp); // file loader
17             this.dict = new FlappDict(); // content dictionary
18             this.movieClip = new FlappMovieClip(); // root MC
19             loader.fromURL(this.url, this.dict, this.movieClip);
20             this.canvas = new FlappCanvas(this.canvas);
21             this.run(this.dict, this.movieClip, this.canvas);
22         },
23         setHeader: function(header) {
24 //          this.frameTick = 1000 / header.framerate;
25             this.frameTick = 1000;
26             this.movieClip.totalframes = header.framecount;
27         },
28         run: function(dict, movieClip, canvas) {
29             console.debug("Flapp::run");
30             var flapp = this;
31             this.canvas = canvas;
32             this.tick(flapp, this.dict, this.movieClip);
33         },
34         tick: function(flapp, dict, movieClip) {
35             console.debug("Flapp::tick "+movieClip.currentFrame);
36             setTimeout(flapp.tick, flapp.frameTick, flapp, dict, movieClip);
37             if (movieClip.control(dict)) {
38                 movieClip.action();
39                 movieClip.render(flapp.canvas);
40                 movieClip.increment();
41             }
42         }
43     };
44     global.Flapp = Flapp;
45 })(this);