Jump to content

Setting dynamic animation speed in melonjs version 4+


01271
 Share

Recommended Posts

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.

Link to comment
Share on other sites

  • 3 weeks later...

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.:)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...