# HG changeset patch # User wycc # Date 1287676574 -28800 # Node ID 85b647f5aeffbd60d248a30cd2e7b6ff634dabfb # Parent a934ad0c89685042eff291370997ed3213a9434b Add callback after the animation is finished. diff -r a934ad0c8968 -r 85b647f5aeff nodejs/animate.js --- a/nodejs/animate.js Tue Oct 19 04:07:47 2010 +0800 +++ b/nodejs/animate.js Thu Oct 21 23:56:14 2010 +0800 @@ -211,6 +211,10 @@ if (now >= this.end) { this.timer.stop(); now = this.end; + if (this.callback_end) { + this.callback_end(); + this.callback_end=null; + } } if (now < this.startmove) return; var per = (now-this.startmove)/this.duration/1000; @@ -238,18 +242,30 @@ function linear_finish() { this.action.draw(1); + if (this.callback_end) { + this.callback_end(); + this.callback_end=null; + } } function linear(action,start, duration) { this.action = action; this.duration = duration; this.starttime = start; + this.callback_end = null; this.timer=null; } + +function linear_callback(cb) +{ + this.callback_end = cb; +} + linear.prototype.update = linear_update; linear.prototype.start = linear_start; linear.prototype.stop = linear_stop; linear.prototype.finish = linear_finish; +linear.prototype.callbackAtEnd = linear_callback; exports.linear = linear; @@ -324,11 +340,13 @@ } } -exports.run = function(actions,start,duration) { +exports.run = function(actions,start,duration,cb) { + var li; for(a in actions) { - var li = new linear(actions[a],start,duration); + li = new linear(actions[a],start,duration); li.start(); } + li.callbackAtEnd(cb); } exports.runexp=function(actions,start,exp) { sys.puts("This function is not implemented yet");