OSDN Git Service

- frameTick を 1000 に (開発中はしばらくコレで)
authorYoshihiro Yamazaki <yoya@awm.jp>
Mon, 26 Nov 2012 17:40:22 +0000 (02:40 +0900)
committerYoshihiro Yamazaki <yoya@awm.jp>
Mon, 26 Nov 2012 17:40:22 +0000 (02:40 +0900)
- movieClip.increment 新設 (currentFrame の inc)
- movieClip コンストラクタに name, matrix, colorTransform を追加
- FlappDisplay を新設 (DisplayList の格納オブジェクト)
- control で display list を操作する処理を追加 (placeobject)
- playing フラグ, loop フラグを追加
- action の受け口を追加
  - Variable 処理の受け口を追加
  - GotoFrame, GotoLabel の受け口を追加
- actionTagList を新設 (ControlTagsList から分離)
- control, action, render, increment の子供MC処理を追加

display.js [new file with mode: 0644]
main.js
movieclip.js

diff --git a/display.js b/display.js
new file mode 100644 (file)
index 0000000..678d39e
--- /dev/null
@@ -0,0 +1,22 @@
+(function(global) {
+    var FlappDisplay = function() {
+       this.characters = {};
+       this.places = {};
+    };
+    FlappDisplay.prototype = {
+       set: function(depth, character, place) {
+           if (character) {
+               this.characters[depth] = character;
+           }
+           this.places[depth] = place;
+       },
+       get: function(depth) {
+           return [this.characters[depth], this.places[depth]];
+       },
+       del: function(depth) {
+           delete this.characters[depth];
+           delete this.places[depth];
+       }
+    };
+    global.FlappDisplay = FlappDisplay;
+})(this);
diff --git a/main.js b/main.js
index 7517ed3..f97e869 100644 (file)
--- a/main.js
+++ b/main.js
@@ -6,7 +6,8 @@
        this.canvas = document.getElementById(canvas_id);
        global.flapp = this; // debug
        this.header = null
-       this.frameTick = 0.1; // default
+//     this.frameTick = 1000 / 10; // default 0.1[sec]
+       this.frameTick = 1000; // default
     };
     Flapp.prototype = {
        play: function() {
            this.run(this.dict, this.movieClip, this.canvas);
        },
        setHeader: function(header) {
-           this.frameTick = 1000 / header.framerate;
+//         this.frameTick = 1000 / header.framerate;
+           this.frameTick = 1000;
            this.movieClip.totalframes = header.framecount;
        },
        run: function(dict, movieClip, canvas) {
            console.debug("Flapp::run");
            var flapp = this;
            this.canvas = canvas;
-           this.matrix = FlappSWFMatrix.identity();
            this.tick(flapp, this.dict, this.movieClip);
        },
        tick: function(flapp, dict, movieClip) {
-           console.debug("Flapp::tick");
-//         setTimeout(flapp.tick, flapp.frameTick, flapp, dict, movieClip);
+           console.debug("Flapp::tick "+movieClip.currentFrame);
+           setTimeout(flapp.tick, flapp.frameTick, flapp, dict, movieClip);
            if (movieClip.control(dict)) {
                movieClip.action();
-               movieClip.render(flapp.canvas, flapp.matrix);
+               movieClip.render(flapp.canvas);
+               movieClip.increment();
            }
        }
     };
index c0de00c..5c3af2a 100644 (file)
@@ -1,7 +1,10 @@
 (function(global) {
-    var FlappMovieClip = function(parentMovieClip) {
+    var FlappMovieClip = function(parentMovieClip, name, matrix, colorTransform) {
        this.parentMovieClip = parentMovieClip?parentMovieCli:this;
        this.rootMovieClip = parentMovieClip?parentMovieClip.rootMovieClip:this;
+       this.name = name?name:'';
+       this.matrix = matrix;
+       this.colorTransform = colorTransform;
        this.childMovieClips = {}; // name => movieClip
        this.clearControlTags();
        //
        this.canvas = canvas;
        this.canvasDirty = false; // dirtyFlag
        //
-       this.displayList = {}; // depth => [tag, matrix, colorTransform]
+       this.displayList = new FlappDisplay();
        //
        this.totalframes = 0;
        this.currentFrame = 0;
+       this.playing = true;
+       // this.loop = true;
+       this.loop = false;
+       var actionVarriableTable = {};
+       var actionVarriablOrigKeys = {};
     };
     FlappMovieClip.prototype = {
        clearControlTags: function(controlTag) {
            this.controlTagsList = [[]]; //
+           this.actionTagsList = [[]];
            this.labelMap = {}; // label => frameNum
            this.framesLoaded = 0;
        },
        appendControlTag: function(controlTag) {
            // console.debug("FlappMovieClip::appendControlTag");
+           if (controlTag.code === 12) { // DoAction
+               this.actionTagsList[this.framesLoaded].push(controlTag);
+               return ;
+           }
            this.controlTagsList[this.framesLoaded].push(controlTag);
            if (controlTag.code === 1) { // ShowFrame
                this.controlTagsList.push([]);
+               this.actionTagsList.push([]);
                this.framesLoaded++;
            } else if (controlTag.code === 43) { // FrameLabel
                this.labelMap[controlTag.name] = this.framesLoaded;
            }
        },
        control: function(dict) {
-           console.debug("FlappMovieClip::control");
-           var tag, i, l;
            if (this.framesLoaderd < this.totalframes) { // imcomplete
                if (this.currentFrame < this.framesLoaderd) {
                    return false; // idle
                }
            }
+           for (var mc in this.childMovieClips) {
+               this.childMovieClips[mc].control(dict);
+           }
+           if (this.playing) {
+               this.controlThis(dict);
+           }
+           return true;
+       },
+       controlThis: function(dict) {
+           console.debug("FlappMovieClip::controlThis");
+           var tag, i, l;
+           var defineTag;
+           if ((this.currentFrame < 0 ) || (this.totalframes <= this.currentFrame)) {
+               this.currentFrame = 0;
+           }
            var controlTags = this.controlTagsList[this.currentFrame];
-           this.actionTagList = [];
+
            for (i = 0, l = controlTags.length ; i < l ; i++) {
-               tag = this.controlTags[i];
+               tag = controlTags[i];
                switch (tag.code) {
                case 1: // ShowFrame
                    break;
-               case 12: // DoAction
-                   this.actionTagList.push(tag);
-                   break;
                case 26: // PlaceObject2
                    // set display List;
+                   if (tag.id === null) {
+                       defineTag = null;
+                   } else {
+                       defineTag = dict.get(tag.id);
+                   }
+                   this.displayList.set(tag.depth, defineTag, tag);
                    break;
                }
            }
-           this.currentFrame = 0;
-           return true;
        },
        action: function() {
-           console.debug("FlappMovieClip::action");
-           var tag, i, l;
-           for (i = 0, l = this.actionTagList.length ; i < l ; i++) {
-               tag = this.actionTagList[i];
-               ;
+           for (var mc in this.childMovieClips) {
+               this.childMovieClips[mc].action();
+           }
+           if (this.playing) {
+               this.actionThis();
            }
+
        },
-       render: function(canvas, matrix, colorTransform) {
-           console.debug("FlappMovieClip::render");
+       actionThis: function() {
+           console.debug("FlappMovieClip::actionThis");
+           var actionTags = this.actionTagsList[this.currentFrame];
+           for (var i = 0, l = actionTags.length ; i < l ; i++) {
+               var tag = actionTags[i];
+               var movieClip = this;
+               FlappAction.exec(tag, movieClip, this.rootMovieClip);
+           }
+       },
+       increment: function() {
+           for (var mc in this.childMovieClips) {
+               this.childMovieClips[mc].increment();
+           }
+           if (this.playing) {
+               this.incrementThis();
+           }
+       },
+       incrementThis: function() {
+           this.currentFrame++;
+           if (this.totalframes <= this.currentFrame) {
+               if (this.loop) {
+                   this.currentFrame = 0; // play
+               } else {
+                   this.playing = false;
+               }
+           }
+           if (this.totalframes === 1) {
+               this.playing = false;
+           }
+       },
+       render: function(canvas) {
+           for (var mc in this.childMovieClips) {
+               this.childMovieClips[mc].render(canvas);
+           }
+           if (this.playing) {
+               this.incrementThis();
+           }
+       },
+       renderThis: function(canvas) {
+           console.debug("FlappMovieClip::renderThis");
            
+       },
+       setVariable: function(key, value) {
+           var lcKey = key.toLowerCase();
+           actionVarriableTable[lcKey] = value;
+           actionVarriablOrigKeys[lcKey] = key;
+       },
+       getVariable: function(key) {
+           var lcKey = key.toLowerCase();
+           if (lcKey in actionVarriableTable) {
+               return actionVarriableTable[lcKey];
+           }
+           return null;
+       },
+       gotoFrame: function(frameNum) {
+           this.currentFrame = frameNum;
+       },
+       gotoLabel: function(frameLabel) {
+           frameNum = labelMap[frameLabel];
+           this.currentFrame = frameNum;
        }
     };
     global.FlappMovieClip = FlappMovieClip;