Page 1 of 1

Updating Counters after animation delay

Posted: 13 February 2017, 11:24
by Morgalad
Hi fellow devs,

I'm wondering if there is a more ellegant way to update a counter with some delay after a slideTemporaryObject.

In my project I move some tokens from one location to other and then updating a counter on the board (similar to the Tokaido animation when getting coins). The problem is that the counter on the board is updated much before the first item arrives to it and does not seem to be consistent.

I'm thinking about adding a setTimeout on the update of the innerhtml of the counter or some other "sleep" but I'm wondering if there is a better way to do it with dojo or similar.

Re: Updating Counters after animation delay

Posted: 14 February 2017, 00:24
by Morgalad
I got it!

After a couple of hours reading the dojo documentation and looking at the Ly_studio js I found a very ellegant method.

Code: Select all

		slideTemporaryObjectAndIncCounter: function( mobile_obj_html , mobile_obj_parent, from, to, duration, delay ) 
		{
			var obj = dojo.place(mobile_obj_html, mobile_obj_parent );
			dojo.style(obj, "position", "absolute");
			dojo.style(obj, "left", "0px");
			dojo.style(obj, "top", "0px");
			this.placeOnObject(obj, from);
			
			var anim = this.slideToObject(obj, to, duration, delay );
			
			this.queue.push(to);
            
			dojo.connect(anim, "onEnd", this, 'incAndDestroy' );
			anim.play();
			return anim;
			},
	
 
		incAndDestroy : function(node) 
		{				
				dojo.destroy(node);
				target=this.queue.shift();
				dojo.byId(target).innerHTML=eval(dojo.byId(target).innerHTML) + 1;
		}, 

Remember to create the queue array in your getdatas .This could be very useful.

Re: Updating Counters after animation delay

Posted: 14 February 2017, 17:34
by Morgalad
Knowing this I'm also applying this technique to other methods:

Code: Select all

		slideToObjectAndDestroyAndIncCounter: function( mobile_obj , to, duration, delay ) 
		{
			var obj = dojo.byId(mobile_obj );
			dojo.style(obj, "position", "absolute");
			dojo.style(obj, "left", "0px");
			dojo.style(obj, "top", "0px");
			var anim = this.slideToObject(obj, to, duration, delay );
			
			this.queue.push(to);
            
			dojo.connect(anim, "onEnd", this, 'incAndDestroy' );
			anim.play();
			return anim;
			},
			

Re: Updating Counters after animation delay

Posted: 14 February 2017, 22:25
by Andy_K
Great work. Just the sort of thing which would be useful in a common community code library :)