I\'m building a game with move.js
for animation, but it takes too long so when the player click on the right solution it displays the winning message before the rig
Edit, Added callback function to .end()
to include deferred.notify
. See comments , Move#end([fn])
Try
var deferred = new $.Deferred();
click(e); // `e` undefined ?
deferred.progress(function(msg) {
// `this` within `deferred`
// references `deferred` object ,
// try `obj.checkWin()`, `obj.nextLevel()`
if (obj.checkWin()) {
alert(msg);
obj.nextLevel();
}
});
function click(e) {
// `e` undefined ?
move(e)
.set('background-color','black')
// `.delay()` accepts `number` as argument ?
.delay('0.1s')
// see comments ,
// http://visionmedia.github.io/move.js/#example-11
.end(function() {
deferred.notify("you won !");
});
};
jsfiddle http://jsfiddle.net/guest271314/4Av4Z/