OSDN Git Service

- instance 化した defineTag を FlappObject として処理
authorYoshihiro Yamazaki <yoya@awm.jp>
Fri, 7 Dec 2012 17:11:53 +0000 (02:11 +0900)
committerYoshihiro Yamazaki <yoya@awm.jp>
Fri, 7 Dec 2012 17:11:53 +0000 (02:11 +0900)
src/main.js
src/movieclip.js
src/shape.js

index a371f3a..8a61481 100644 (file)
@@ -26,7 +26,9 @@ Flapp.prototype = {
         var flapp = this;
         var loader = new FlappLoader(flapp); // file loader
         this.dict = new FlappDict(); // content dictionary
-        this.movieClip = new FlappMovieClip("_root", null, null, null); // root MC
+       var m = FlappSWFMatrix;
+       var matrix = m.multiply(m.identity(), 20);
+        this.movieClip = new FlappMovieClip("_root", matrix, null); // root MC
         loader.fromURL(this.url, this.dict, this.movieClip);
         this.canvas = new FlappCanvas(this.canvas);
         this.run(this.dict, this.movieClip, this.canvas);
index a6da73d..a3f898f 100644 (file)
@@ -1,4 +1,5 @@
 goog.provide('FlappMovieClip');
+goog.require('FlappObject');
 goog.require('FlappDisplay');
 goog.require('FlappShape');
 goog.require('FlappAction');
@@ -8,15 +9,14 @@ goog.scope(function() {
 /**
  * @constructor
  */
-FlappMovieClip = function(parentMovieClip, name, matrix, colorTransform) {
-    this.OBJECT_TYPE = 2; // 1:Shape, 2: MovieClip
+FlappMovieClip = function(parentMovieClip, matrix, colorTransform) {
     this.parentMovieClip = parentMovieClip?parentMovieClip:null;
     this.rootMovieClip = parentMovieClip?parentMovieClip.rootMovieClip:this;
-    this.name = name?name:'anonymous';
+    this.name = null;
     this.matrix = matrix;
     this.colorTransform = colorTransform;
     this.childMovieClips = {}; // name => movieClip
-    this.childMovieClips_seqnum = 1; // for name movieClip
+    this.instanceSeqno = 1; // for name object (movieClip, etc...)
     this.clearControlTags();
     //
     this.prevShowFramePos = 0;
@@ -28,6 +28,7 @@ FlappMovieClip = function(parentMovieClip, name, matrix, colorTransform) {
     this.canvasDirty = false; // dirtyFlag
     //
     this.displayList = new FlappDisplay();
+    this.displayObjectLifeSpan = {}; // for gotoFrame
     //
     this.totalframes = 0;
     this.currentFrame = 0;
@@ -107,25 +108,34 @@ FlappMovieClip.prototype = {
             case 26: // PlaceObject2
                 // set display List;
                 var obj = null;
-                if (tag.move) {
-                    this.displayList.set(tag.depth, obj, tag);
+                if (tag.move && (tag.id === null)) {
+                    this.displayList.move(tag.depth, tag);
                 } else {
+                   if (tag.move) {
+                       obj = this.displayList.get(tag.depth);
+                       if (obj === null) {
+                           console.error("Can't get DisplayObject by depth:"+tag.depth);
+                       }
+                       if (obj.code === 39) { // DefineSprite
+                           this.deleteChildMovieClip(obj.name);
+                       }
+                       this.displayList.del(tag.depth);
+                   }
                     defineTag = dict.get(tag.id);
-                    console.log(tag);
-                    if (defineTag.code === 39) { // DefineSprite
-                        var name = tag.name;
-                        if (name === null) {
-                            name = "instance"+this.childMovieClips_seqnum;
-                            defineTag.name = name;
-                            this.childMovieClips_seqnum++;
-                        }
-                        obj = new FlappMovieClip(this, name, tag.matrix, tag.colorTransform);
-                        obj.setControlTags(defineTag.controlTags);
-                        this.addChildMovieClip(name, obj);
-                    } else if (defineTag.code === 2) { // DefineShape
-                        obj = new FlappShape(name, tag.matrix, tag.colorTransform);
-                        console.log(obj);
-                        obj.loadShapeTag(defineTag);
+                   if (defineTag === null) {
+                       console.error("defineTag === undefined");
+                       return ;
+                   }
+                    var name = tag.name;
+                    if ((name === null) && (defineTag.code === 39)) {
+                        name = "instance"+this.instanceSeqno;
+                        tag.name = name;
+                       this.instanceSeqno++;
+                    }
+                    obj = FlappObject.factory(this, name, defineTag, tag);
+//                    console.debug(obj);
+                   if (defineTag.code === 39) { // DefineSprite
+                       this.addChildMovieClip(name, obj);
                     }
                     this.displayList.set(tag.depth, obj, tag);
                     break;
@@ -178,12 +188,8 @@ FlappMovieClip.prototype = {
         var depthList = this.displayList.descSortedDepth();
         for (var i = 0, l = depthList.length  ; i < l ; i++) {
             var depth = depthList[i];
-            var obj = this.displayList.getObj(depth);
-            if (obj.OBJECT_TYPE === 2) { // MovieClip
-                obj.render(this.canvas);
-            } else if ((obj.OBJECT_TYPE === 2) && (this.playing == true)) {
-                obj.render(this.canvas);
-            }
+            var obj = this.displayList.get(depth);
+           obj.render(this.canvas);
         }
     },
     setVariable: function(key, value) {
index a926e21..d66ac24 100644 (file)
@@ -5,8 +5,11 @@ goog.scope(function() {
 /**
  * @constructor
  */
-FlappShape = function(name, matrix, colorTransform) {
+FlappShape = function(matrix, colorTransform) {
     this.OBJECT_TYPE = 1; // 1:Shape, 2:MovieClip
+    this.name = null;
+    this.matrix = matrix;
+    this.colorTransform = colorTransform;
     this.canvas = document.createElement('canvas');
     this.canvas.width = 240; // XXX
     this.canvas.height = 240; // XXX
@@ -18,6 +21,9 @@ FlappShape.prototype = {
         ;
     },
     render: function(canvas) {
+        
+    },
+    destroy: function(canvas) {
         ;
     }
 };