OSDN Git Service

tweetの修正
[yukkurioverwint/YukkuriOverwinter.git] / class.js
index 7f07cc5..7dfc67a 100644 (file)
--- a/class.js
+++ b/class.js
@@ -1,5 +1,8 @@
 TTweet = enchant.Class.create(enchant.Sprite, {
-       initialize : function(w, h) {
+       initialize : function(yukkuri, w, h) {
+               this.x = 0;
+               this.y = 0;
+               this.yukkuri = yukkuri;
                this.lifetime = 0;
                enchant.Sprite.call(this, w, h + TTweet.TAIL);
                this.image = new Surface(w, h + TTweet.TAIL);
@@ -19,6 +22,7 @@ TTweet = enchant.Class.create(enchant.Sprite, {
                        ld : {x:  0+s, y:h+t-s}
                };
                this.image.context.font = "12px 'Times New Roman'";
+               var self = this;
                this.addEventListener('enterframe', function(){
                        if((this.age % 15) == 0){
                                this.lifetime--;
@@ -27,6 +31,9 @@ TTweet = enchant.Class.create(enchant.Sprite, {
                                this.lifetime = 0;
                                this.opacity = 0;
                        }
+                       this.x = self.yukkuri.getX() - self.width/4 - self.yukkuri.getWidth() / 2;
+                       this.y = self.yukkuri.getY() - self.height - self.yukkuri.getHeight() / 2;
+                       // this._tweet.text(text, this.getX() - this._tweet.width/4, this.getY() - this._tweet.height);
                });
        },
        reDraw : function() {
@@ -76,22 +83,20 @@ TTweet = enchant.Class.create(enchant.Sprite, {
                };
        },
        text : function(text, x, y) {
+               this.x = this.yukkuri.getX() - this.width/4 - this.yukkuri.getWidth() / 2;
+               this.y = this.yukkuri.getY() - this.height - this.yukkuri.getHeight() / 2;
+               x = this.x;
+               y = this.y;
                this.clear();
                this.opacity = 0.8;
 
                this.reDraw();
                with(this.image.context) {
-                       // var size = measureText(text);
                        fillStyle = 'black';
                        textAlign = 'center';
                        textBaseline = 'middle';
                        this.x = x;
                        this.y = y;
-                       // fillText(text,this.width/2,this.height/2);
-                       // console.log(size);
-                       // this.width = size;
-                       // console.log(this.width);
-                       // this.reDraw();
                        var textList = text.split("\n");
                        var len = textList.length / 2;
                        var height = (this.height/(1 + len));
@@ -368,6 +373,11 @@ GWindow = enchant.Class.create(enchant.Sprite, {
                scene.addChild(this);
        }
 });
+App.YUtil = enchant.Class.create(enchant.Sprite,{
+       randomLooks : function(){
+               return rand(_.size(ELooks));
+       }
+});
 
 
 //how to use