osinski Posted September 24, 2014 Share Posted September 24, 2014 Hey!I'm trying to use listener onComplete for animation:var boom_tile = game.add.sprite(checked_tile_x, checked_tile_y, "boom");boom_tile.anchor.setTo(0.5, 0.5);boom_tile.animations.add("boom").onComplete.add(function(){console.log("ON COMPLETE!")});But got error: TypeError: boom_tile.animations.add(...).onComplete.add is not a function Could you help me? Link to comment Share on other sites More sharing options...
lewster32 Posted September 24, 2014 Share Posted September 24, 2014 Hmm, it seems like it should work, though I've not chained it like that before - does this work?var anim = boom_tile.animations.add("boom");anim.onComplete.add(function() { console.log("ON COMPLETE!");});anim.play();If not, it may give you a better indication of where the error lies at least... Link to comment Share on other sites More sharing options...
osinski Posted September 24, 2014 Author Share Posted September 24, 2014 Its my function, I changed it like your example:function removeTiles (i, j){ var checked_tile = tilesList[i][j]; var checked_tile_x = checked_tile.x; var checked_tile_y = checked_tile.y; var boom_tile = game.add.sprite(checked_tile_x, checked_tile_y, "boom"); boom_tile.anchor.setTo(0.5, 0.5); //add animation var anim = boom_tile.animations.add("boom"); anim.onComplete.add(function() { console.log("ON COMPLETE!"); }); anim.play();}And got same error: TypeError: anim.onComplete.add is not a function Link to comment Share on other sites More sharing options...
lewster32 Posted September 24, 2014 Share Posted September 24, 2014 Hang on, I've just realised you're not providing any frames to the add method! In order to add an animation, you should at the very least provide one or more frames as the second parameter. This is marked as optional in the docs but I'd try it anyway.var anim = boom_tile.animations.add("boom", [0, 1]); Link to comment Share on other sites More sharing options...
osinski Posted September 24, 2014 Author Share Posted September 24, 2014 It's no difference:function removeTiles (i, j){ var checked_tile = tilesList[i][j]; var checked_tile_x = checked_tile.x; var checked_tile_y = checked_tile.y; var boom_tile = game.add.sprite(checked_tile_x, checked_tile_y, "boom"); boom_tile.anchor.setTo(0.5, 0.5); //add animation var anim = boom_tile.animations.add("boom", [1, 2], 2); anim.onComplete.add(function() { console.log("ON COMPLETE!"); }); anim.play();}Again TypeError: anim.onComplete.add is not a function. Without onComplete all works nice. Link to comment Share on other sites More sharing options...
lewster32 Posted September 24, 2014 Share Posted September 24, 2014 Can you confirm which version of Phaser you're using please? Also, could to add console.log(anim); to your code to see what's actually being returned? Link to comment Share on other sites More sharing options...
osinski Posted September 24, 2014 Author Share Posted September 24, 2014 Oh! You are right!! I have old version of Phaser. I'll try remake it with new one. Thank you!!! Link to comment Share on other sites More sharing options...
Recommended Posts