From: nagomi Date: Fri, 20 Sep 2013 17:09:49 +0000 (+0900) Subject: add to event class X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ad83aa5d88cef97c10ec05378db0f6a8bb547b48;p=yukkurioverwint%2FYukkuriOverwinter.git add to event class --- diff --git a/main.js b/main.js index 5ab849a..211cea0 100644 --- a/main.js +++ b/main.js @@ -120,6 +120,8 @@ window.onload = function(){ case EAction.DEAD: this.dead(); break; + case EAction.EAT: + break; } }, move : function(){ @@ -243,6 +245,7 @@ window.onload = function(){ this.moveEvent = new MoveEvent({ "type": 'food', "targetNode": node, + "action": this, "myYukkuri": this.yukkuri }); return; @@ -254,9 +257,20 @@ window.onload = function(){ this.status = EAction.WALK; } }); - var MoveEvent = enchant.Class.create({ + var Event = enchant.Class.create({ + initialize: function (){ + }, + onactionstart:function(e){ + }, + onactiontick:function(e){ + }, + onactionend:function(e){ + } + }); + var MoveEvent = enchant.Class.create(Event,{ initialize: function (_data){ this.data = _data; + var self = this; var yukkuri = this.data.myYukkuri; var node = this.data.targetNode; //food distance @@ -264,15 +278,26 @@ window.onload = function(){ yukkuri.vx = node.x - yukkuri.getX(); yukkuri.vy = node.y - yukkuri.getY(); var frame = 150; - yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame); - - yukkuri.addEventListener(enchant.Event.ACTION_END, function(evt) { - console.log("end"); + yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, { + "onactionstart": this.onactionstart, + "onactiontick": this.onactiontick, + "onactionend": this.onactionend }); - - yukkuri.tweet("ゆゆ??\nたべものさんはっけんなのぜ!"); } }, + onactionstart:function(e){ + if(typeof e === "undefined")return; + yukkuri.tweet("ゆゆ??\nたべものさんはっけんなのぜ!"); + }, + onactiontick:function(e){ + if(typeof e === "undefined")return; + console.log("onactiontic"); + }, + onactionend:function(e){ + if(typeof e === "undefined")return; + yukkuri.tweet("む~しゃむ~しゃするのぜ!"); + self.data.action = EAction.EAT; + }, run: function(){ if(this.data.type == "food"){ @@ -340,28 +365,22 @@ window.onload = function(){ moveBy:function(x, y, time, eventFunctions){ // this.imgGroup.tl.moveBy(x, y, time, enchant.Easing.SIN_EASEINOUT); var self = this; - console.log("moveby"); + var params = { + x: function() { + return self.imgGroup.x + x; + }, + y: function() { + return self.imgGroup.y + y; + }, + time: time, + easing: enchant.Easing.SIN_EASEINOUT + }; if(eventFunctions !== undefined){ - // for(var func in eventFunctions){ - // eventFunctions[func]; - // } + for(var key in eventFunctions){ + params[key] = eventFunctions[key]; + } } - this.imgGroup.tl.tween({ - x: function() { - return self.imgGroup.x + x; - }, - y: function() { - return self.imgGroup.y + y; - }, - time: time, - easing: enchant.Easing.SIN_EASEINOUT, - "onactionstart": function(e){ - console.log("action start"); - }, - "onactionend": function(e){ - console.log("actionenddd"); - } - }); + this.imgGroup.tl.tween(params); }, act: function(){