01271 Posted May 5, 2017 Share Posted May 5, 2017 The documentation for sprite animation is a bit out of date and a new method setAnimationSpeed(speed) or setAnimationSpeed(identifier, speed) should be added. I have a sprite and an animation this._super(me.Sprite, 'init', [339, 480, settings]); this.addAnimation('normal', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],100); this.setCurrentAnimation('normal'); This animates at a delay of 100 ms. I can change the animation delay by adding another parameter to the addAnimation method. I could not change the delay afterwards with the solutions I found. I have seen this answer: https://groups.google.com/forum/#!topic/melonjs/mk6mVcMoVKo but it is no longer relevant. this.anim.normal.animationspeed isn't a part of melonjs anymore and changing the other animationspeed settings doesn't have any effect. This is I think, because of a change from a 'global' animation delay to a frame-based animation delay. The new method for changing the speed of an animation should now be: setAnimationSpeed: function(identifier, speed) { for (var i = this.anim[identifier].frames.length - 1; i >= 0; i--) { this.anim[identifier].frames[i].delay = speed; } } There should be a note on the sprite and/or renderable pages about the animation speed able to be individually set on a per-frame basis. It could be useful for example if some character is looking to the left and then turning quickly to the right the frame set wouldn't have to look like this: [0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[0],[1],[2],[3],[4],[5],[5],[5],[5],[5],[5],[5],[5] and could just have a long delay on the 0 and 5 frames. Every X.0.0 version should result in a new version of the wiki and documentation with the changes you're making. Relevant changes to each could be made to affected pages after. Quote Link to comment Share on other sites More sharing options...
Parasyte Posted May 6, 2017 Share Posted May 6, 2017 Can I ask why you're changing the animation speed after the animation is created? We would recommend you just create additional animations if you need a slower or faster version using the same frames but a different speed. Quote Link to comment Share on other sites More sharing options...
Hashasm Posted May 23, 2017 Share Posted May 23, 2017 hi @01271 you try this it will come this._super(me.Sprite, 'init', [339, 480, settings]); this.addAnimation('normal',[{ name: 0, delay: 600 }, { name: 1, delay: 600 },{name: 2, delay: 600 },{name: 3, delay: 600 },{name: 4, delay: 600 },{name: 5, delay: 600 },{name: 6, delay: 600 },{name: 7, delay: 600 },{name: 8, delay: 600 },{name: 9, delay: 600 }]); this.setCurrentAnimation('normal'); give delay how much you want. 01271 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.