1 TTweet = enchant.Class.create(enchant.Sprite, {
2 initialize : function(w, h) {
4 enchant.Sprite.call(this, w, h + TTweet.TAIL);
5 this.image = new Surface(w, h + TTweet.TAIL);
16 lt : {x: 0+s, y: t+s},
17 rt : {x: w-s, y: t+s},
18 rd : {x: w-s, y:h+t-s},
19 ld : {x: 0+s, y:h+t-s}
21 this.image.context.font = "12px 'Times New Roman'";
22 this.addEventListener('enterframe', function(){
23 if((this.age % 15) == 0){
26 if(this.lifetime <= 0){
34 var o = this.outCurve;
35 with(this.image.context) {
37 strokeStyle = 'black';
39 moveTo(o.lt.x, o.lt.y+c);
40 quadraticCurveTo(o.lt.x, o.lt.y, o.lt.x+c, o.lt.y);
41 lineTo(o.rt.x-c, o.rt.y);
42 quadraticCurveTo(o.rt.x, o.rt.y, o.rt.x, o.rt.y+c);
43 lineTo(o.rd.x, o.rd.y-c);
44 quadraticCurveTo(o.rd.x, o.rd.y, o.rd.x-c, o.rd.y);
45 lineTo(o.ld.x+c, o.ld.y);
46 quadraticCurveTo(o.ld.x, o.ld.y, o.ld.x, o.ld.y-c);
49 // lineTo(this.width/2-4,_height + TTweet.TAIL);
50 // lineTo(this.width/2,_height + 0);
51 // lineTo(this.width/2+4,_height + TTweet.TAIL);
60 var o = this.outCurve;
62 with(this.image.context) {
66 moveTo(i.lt.x, o.lt.y+c);
67 quadraticCurveTo(i.lt.x, i.lt.y, o.lt.x+c, i.lt.y);
68 lineTo(o.rt.x-c, i.rt.y);
69 quadraticCurveTo(i.rt.x, i.rt.y, i.rt.x, o.rt.y+c);
70 lineTo(i.rd.x, o.rd.y-c);
71 quadraticCurveTo(i.rd.x, i.rd.y, o.rd.x-c, i.rd.y);
72 lineTo(o.ld.x+c, i.ld.y);
73 quadraticCurveTo(i.ld.x, i.ld.y, i.ld.x, o.ld.y-c);
78 text : function(text, x, y) {
83 with(this.image.context) {
84 // var size = measureText(text);
87 textBaseline = 'middle';
90 // fillText(text,this.width/2,this.height/2);
93 // console.log(this.width);
95 var textList = text.split("\n");
96 var len = textList.length / 2;
97 var height = (this.height/(1 + len));
98 this.fillTextLine(text,this.width/2, height);
103 fillTextLine : function(text, x, y) {
104 var textList = text.split("\n");
105 var lineHeight = this.image.context.measureText("あ").width + 2;
107 textList.forEach(function(text, i) {
108 self.image.context.fillText(text, x, y + lineHeight * i);
119 var Box = enchant.Class.create(enchant.Sprite, {
120 initialize : function(ctl, node, x, y, w, h) {
121 enchant.Sprite.call(this, w, h + TTweet.TAIL);
131 ctl.game.rootScene.addEventListener('touchstart', this.touchstart(this));
132 ctl.backgroundMap.addChild(this);
136 this.image = new Surface(w, h + TTweet.TAIL);
139 var c = TTweet.CURVE;
147 lt : {x: 0+s, y: t+s},
148 rt : {x: w-s, y: t+s},
149 rd : {x: w-s, y:h+t-s},
150 ld : {x: 0+s, y:h+t-s}
152 this.image.context.font = "12px 'Times New Roman'";
154 this.addEventListener('enterframe', function(){
155 if((this.age % BASE_FPS) == 0){
159 if(this.lifetime <= 0){
162 this.removeEventListener('enterframe', arguments.callee);
167 reDraw : function() {
168 var c = TTweet.CURVE;
169 var o = this.outCurve;
170 with(this.image.context) {
172 strokeStyle = 'black';
174 moveTo(o.lt.x, o.lt.y+c);
175 quadraticCurveTo(o.lt.x, o.lt.y, o.lt.x+c, o.lt.y);
176 lineTo(o.rt.x-c, o.rt.y);
177 quadraticCurveTo(o.rt.x, o.rt.y, o.rt.x, o.rt.y+c);
178 lineTo(o.rd.x, o.rd.y-c);
179 quadraticCurveTo(o.rd.x, o.rd.y, o.rd.x-c, o.rd.y);
180 lineTo(o.ld.x+c, o.ld.y);
181 quadraticCurveTo(o.ld.x, o.ld.y, o.ld.x, o.ld.y-c);
189 var c = TTweet.CURVE;
190 var o = this.outCurve;
191 var i = this.inCurve;
192 with(this.image.context) {
196 moveTo(i.lt.x, o.lt.y+c);
197 quadraticCurveTo(i.lt.x, i.lt.y, o.lt.x+c, i.lt.y);
198 lineTo(o.rt.x-c, i.rt.y);
199 quadraticCurveTo(i.rt.x, i.rt.y, i.rt.x, o.rt.y+c);
200 lineTo(i.rd.x, o.rd.y-c);
201 quadraticCurveTo(i.rd.x, i.rd.y, o.rd.x-c, i.rd.y);
202 lineTo(o.ld.x+c, i.ld.y);
203 quadraticCurveTo(i.ld.x, i.ld.y, i.ld.x, o.ld.y-c);
208 drawBox : function() {
211 text = this.node.getStatusForDisplay();
213 with(this.image.context) {
215 textAlign = 'center';
216 textBaseline = 'middle';
217 var textList = text.split("\n");
218 var len = textList.length / 2;
219 var height = (this.height/(1 + len));
220 this.fillTextLine(text,this.width/2, height);
225 fillTextLine : function(text, x, y) {
226 var textList = text.split("\n");
227 var lineHeight = this.image.context.measureText("あ").width + 2;
229 textList.forEach(function(text, i) {
230 self.image.context.fillText(text, x, y + lineHeight * i);
239 touchstart:function(self){
241 if(typeof e === "undefined")return;
242 // this.removeEventListener('touchstart', arguments.callee);
244 // if(self.x <= e.x && self.x + self.width >= e.x
245 // && self.y <= e.y && self.y + self.height >= e.y
247 if(ctl.isCollision(e, self)){
248 this.removeEventListener('touchstart', arguments.callee);
255 this.parentNode.removeChild(this);
256 ctl.backgroundMap.removeChild(this);
258 this.lifetime = null;
266 //var tweet = new TTweet(128, 64);
267 //tweet.text("ABCDEFG");