OSDN Git Service

matrix で TWIPS 分 20割ったつもりが掛けていたので修正。
[flapp/flapp.git] / src / main.js
1 goog.provide('Flapp');
2 goog.require('FlappLoader');
3 goog.require('FlappDict');
4 goog.require('FlappCanvas');
5 goog.require('FlappMovieClip');
6
7 goog.scope(function() {
8
9 /**
10  * @constructor
11  */
12 Flapp = function(url, canvas_id) {
13     console.debug("Flapp("+url+","+canvas_id+")");
14     this.url = url;
15     this.canvas_id = canvas_id;
16     this.canvas = document.getElementById(canvas_id);
17     goog.global.flapp = this; // debug
18     this.header = null
19 //      this.frameTick = 1000 / 10; // default 0.1[sec]
20     this.frameTick = 1000; // default
21     this.timerId = null;
22 };
23 Flapp.prototype = {
24     play: function() {
25         console.debug("Flapp.prototype.play");
26         var flapp = this;
27         var loader = new FlappLoader(flapp); // file loader
28         this.dict = new FlappDict(); // content dictionary
29         var matrix = FlappSWFMatrix.multiplyScalar(FlappSWFMatrix.identity(), (1/20));
30         this.movieClip = new FlappMovieClip("_root", matrix, null); // root MC
31         loader.fromURL(this.url, this.dict, this.movieClip);
32         this.canvas = new FlappCanvas(this.canvas);
33         this.run(this.dict, this.movieClip, this.canvas);
34     },
35     setHeader: function(header) {
36 //          this.frameTick = 1000 / header.framerate;
37         this.frameTick = 1000;
38         this.movieClip.totalframes = header.framecount;
39         if (typeof this.timerId === 'number') {
40             clearInterval(this.timerId);
41             this.ticks();
42         }
43     },
44     run: function(dict, movieClip, canvas) {
45         console.debug("Flapp::run");
46         var flapp = this;
47         this.canvas = canvas;
48         this.ticks();
49     },
50     ticks: function() {
51         var flapp = this;
52         var dict = this.dict;
53         var movieClip = this.movieClip;
54         var canvas = this.canvas;
55         console.debug("Flapp::ticks "+movieClip.currentFrame);
56         this.timerId = setInterval(function() {
57             if (movieClip.control(dict)) {
58                 movieClip.action();
59                 movieClip.render(canvas);
60                 movieClip.increment();
61             }
62         }, flapp.frameTick);
63     }
64 };
65
66 goog.exportSymbol('Flapp', Flapp);
67 goog.exportSymbol('Flapp.prototype.play', Flapp.prototype.play);
68
69 });