Mercurial > MadButterfly
changeset 1410:afa062941f39
Use closure to replace the function to simplify the code.
author | wycc |
---|---|
date | Wed, 06 Apr 2011 07:52:55 +0800 |
parents | b8ba20b8f91a |
children | 5dd46a4f6257 |
files | nodejs/examples/mce/mainmenu.js |
diffstat | 1 files changed, 32 insertions(+), 93 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/examples/mce/mainmenu.js Wed Apr 06 07:52:13 2011 +0800 +++ b/nodejs/examples/mce/mainmenu.js Wed Apr 06 07:52:55 2011 +0800 @@ -21,8 +21,8 @@ } MainMenu.prototype.init=function() { - app.loadSVG("main.svg"); - app.changeScene(1); + app.loadSVG("main1.svg"); + app.changeScene(0); var i; var self = this; @@ -40,124 +40,63 @@ } this.line=0; this.item = 0; - - animate.run([new animate.scale(app,this.items[this.item], 1, 1.5)], 0, 0.1); - app.refresh(); - - app.addKeyListener(mbapp.KEY_LEFT, function() { self.key_left();}); - app.addKeyListener(mbapp.KEY_RIGHT, function() { self.key_right();}); - app.addKeyListener(mbapp.KEY_UP, function() {self.key_up();}); - app.addKeyListener(mbapp.KEY_DOWN, function() {self.key_down();}); - app.addKeyListener(mbapp.KEY_ENTER, function() {self.key_enter();}); -} + this.itemToScene=[0,15,31,47,63,79,95]; -MainMenu.prototype.key_left=function () -{ - var old = this.items[this.item]; - this.item = this.item - 1; - if (this.item == -1) { - this.item = 0; - return; - } - - var target = this.items[this.item]; - - old.bbox.update(); - target.bbox.update(); - - var an = new animate.scale(this.app, old, 1/1.1, 1/1.5); - animate.run([an], 0, 0.1); - an = new animate.scale(this.app, target, 1.1, 1.5); - animate.run([an], 0, 0.3); - var sx = target.center.x - this.lightbar.center.x; - var an = new animate.shift(this.app, this.lightbar, sx, 0); - animate.run([an], 0, 0.3); + app.addKeyListener(mbapp.KEY_LEFT, function() { + self.item = self.item - 1; + if (self.item == -1) { + self.item = 0; + return; + } + self.app.runToScene(self.itemToScene[self.item]); + }); + app.addKeyListener(mbapp.KEY_RIGHT, function() { + self.item = self.item + 1; + if (self.item == self.items.length) { + self.item = self.item - 1; + return; + } + self.app.runToScene(self.itemToScene[self.item]); + }); + app.addKeyListener(mbapp.KEY_ENTER, function() { + self.key_enter(); + }); } -MainMenu.prototype.key_right=function() -{ - var old = this.items[this.item]; - this.item = this.item + 1; - if (this.item == this.items.length) { - this.item = this.item - 1; - return; - } - - var target = this.items[this.item]; - - old.bbox.update(); - target.bbox.update(); - - var an = new animate.scale(this.app, old, 1/1.1, 1/1.5); - animate.run([an], 0, 0.1); - an = new animate.scale(this.app, target, 1.1, 1.5); - animate.run([an], 0, 0.3); - var sx = target.center.x - this.lightbar.center.x; - var an = new animate.shift(this.app, this.lightbar, sx, 0); - animate.run([an], 0, 0.3); -} - -MainMenu.prototype.key_up=function() -{ - var old = this.lines[this.line]; - this.line = this.line - 1; - if (this.line == -1) { - this.line = 0; - return; - } - var target = this.lines[this.line]; - var sy = target.center.y - this.lightbar.center.y; - var an = new animate.shift(this.app, this.lightbar, 0, sy); - animate.run([an], 0, 0.3); -} - - -MainMenu.prototype.key_down=function () -{ - var old = this.lines[this.line]; - this.line = this.line + 1; - if (this.line == this.lines.length) { - this.line = this.line - 1; - return; - } - var target = this.lines[this.line]; - var sy = target.center.y - this.lightbar.center.y; - var an = new animate.shift(this.app, this.lightbar, 0, sy); - animate.run([an], 0, 0.3); -} MainMenu.prototype.key_enter=function() { var self = this; var target = this.items[this.item]; - var an = new animate.scale(this.app, target, 1/1.1, 1/1.5); + var an = new animate.scale(this.app, target, 1, 1/1.5); animate.run([an], 0, 0.3,function() { var sx = 259 - target.center.x; var sy = 355 - target.center.y; var an1 = new animate.shift(self.app,target,sx,sy); - animate.run([an1],0,1,function() {self.changePage(self.item);}); + animate.run([an1],0,1,function() { + self.changePage(self.item); + }); }); for(i=0;i<this.items.length;i++) { if (i == this.item) continue; if (i > this.item) { - sx = 1920*2 - this.items[i].center.x; + sx = 1920 - this.items[i].center.x; sy = 0; } else { sx = -this.items[i].center.x*2; sy = 0; } - an = new animate.shift(this.app,this.items[i], sx, sy); - animate.run([an], 0, 2); - alpha = new animate.alpha(this.app,this.items[i], 0); - animate.run([an], 0, 2); + //alpha = new animate.alpha(this.app,this.items[i], 0); + an = new animate.shift(this.app,this.items[i], sx,sy); + animate.run([an], 0, 1); } } MainMenu.prototype.onNextPage=function() { - this.app.changeScene(2); + this.app.changeScene(98); } MainMenu.prototype.changePage=function(item) { - this.epg.getList(item,self.onNextPage()); + this.app.epg.getList(item,this.onNextPage); } exports.MainMenu=MainMenu;