OSDN Git Service

Spriteを組み合わせるFormSpriteを作成。
[yukkurioverwint/YukkuriOverwinter.git] / php / lib / FormSprite.js
1 var FormSprite = enchant.Class.create({
2         initialize: function (){
3                 this.spriteArray = [];
4                 this.id = guid();
5                 this.mainIndex = 0;
6         },
7         addChildAll:function(){
8                 for(var i=0;i<this.spriteArray.length;i++){
9                         this.spriteArray[i].baseX = this.spriteArray[i].x;
10                         this.spriteArray[i].baseY = this.spriteArray[i].y;
11                         this.spriteArray[i].anim = new Animation(this.spriteArray[i]);
12                         this.spriteArray[i].id = guid();
13                         App.backgroundMap.addChild(this.spriteArray[i]);
14                 }
15         },
16         /**
17         attr: 
18                 mainIndex:true/false
19                 type:body/tweet
20         */
21         add : function(sprite, index, attr){
22                 if(attr === undefined)attr = {};
23                 this.spriteArray[index] = sprite;
24                 this.spriteArray[index].type = attr.type;
25                 this.spriteArray[index].scaleValue = attr.scaleValue;
26                 if(attr.mainIndexFlg){
27                         this.mainIndex = index;
28                 }
29                 // this.spriteArray.push(sprite);
30         },
31         remove: function (sprite){
32                 this.spriteArray.remove(sprite);
33         },
34         addX: function(x){
35                 for(var i=0;i<this.spriteArray.length;i++){
36                         var spr = this.spriteArray[i];
37                         spr.x += x;
38                 }
39         },
40         addY: function(y){
41                 for(var i=0;i<this.spriteArray.length;i++){
42                         var spr = this.spriteArray[i];
43                         spr.y += y;
44                 }
45         },
46         getX: function(){
47                 return Math.round(this.spriteArray[this.mainIndex].x,2) - this.spriteArray[this.mainIndex].baseX;
48         },
49         getY: function(){
50                 return Math.round(this.spriteArray[this.mainIndex].y,2) - this.spriteArray[this.mainIndex].baseY;
51         },
52         setX: function(x){
53                 for(var i=0;i<this.spriteArray.length;i++){
54                         var spr = this.spriteArray[i];
55                         spr.x = x + spr.baseX;
56                 }
57         },
58         setY: function(y){
59                 for(var i=0;i<this.spriteArray.length;i++){
60                         var spr = this.spriteArray[i];
61                         spr.y = y + spr.baseY;
62                 }
63         },
64         formScaleX: function(x){
65                 for(var i=0;i<this.spriteArray.length;i++){
66                         var spr = this.spriteArray[i];
67                         if(spr.type == "tweet")continue;
68                         spr.scaleX = x;
69                 }
70         },
71         formScaleY: function(y){
72                 for(var i=0;i<this.spriteArray.length;i++){
73                         var spr = this.spriteArray[i];
74                         if(spr.type == "tweet")continue;
75                         spr.scaleY = y;
76                 }
77         },
78         // tlTween:function(params){
79         //      console.log("tlTween");
80         //      for(var i=0;i<this.spriteArray.length;i++){
81         //              var spr = this.spriteArray[i];
82         //              spr.tl.tween(params);
83         //      }
84         // },
85         tlMoveBy:function(x, y, time, eventFunctions){
86                 var self = this;
87                 for(var i=0;i<this.spriteArray.length;i++){
88                         var spr = this.spriteArray[i];
89                         if(spr.type == "tweet")continue;
90
91                         // var addX = x + spr.baseX;
92                         // var addY = y + spr.baseX;
93                         var addX = x;
94                         var addY = y;
95                         // console.log(i+":spry:" + spr.y);
96                         var params = {
97                                 x: this.paramX(spr.x, addX),
98                                 y: this.paramY(spr.y, addY),
99                                 time: time,
100                                 easing: enchant.Easing.SIN_EASEINOUT
101                         };
102                         if(eventFunctions !== undefined && i == this.mainIndex){
103                                 for(var key in eventFunctions){
104                                         params[key] = eventFunctions[key];
105                                 }
106                         }
107                         spr.tl.tween(params);
108                 }
109         },
110         paramX : function(x, addX){
111                 return x  + addX;
112                 // return function(){
113                 //      return x  + addX;
114                 // }
115         },
116         paramY : function(y, addY){
117                 return y + addY;
118         },
119         tlMoveTo:function(x, y, time, easing ){
120                 for(var i=0;i<this.spriteArray.length;i++){
121                         var spr = this.spriteArray[i];
122                         spr.tl.moveTo(x, y, time, easing);
123                 }
124         },
125         tlQueueLength:function(){
126                 return this.spriteArray[this.mainIndex].tl.queue.length;
127         },
128         animation: function(){
129                 for(var i=0;i<this.spriteArray.length;i++){
130                         var spr = this.spriteArray[i];
131                         if(spr.type == "body"){
132                                 spr.anim.animrun();
133                         }
134                 }
135         },
136         scale: function(_scaleX,_scaleY){
137                 for(var i=0;i<this.spriteArray.length;i++){
138                         var spr = this.spriteArray[i];
139                         if(spr.type == "tweet")continue;
140                         spr.scale(_scaleX, _scaleY);
141                 }
142         },
143 });