Updating Counters after animation delay

Game development with Board Game Arena Studio
Post Reply
User avatar
Morgalad
Posts: 110
Joined: 17 January 2017, 20:46
Contact:

Updating Counters after animation delay

Post 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.
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Morgalad
Posts: 110
Joined: 17 January 2017, 20:46
Contact:

Re: Updating Counters after animation delay

Post 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.
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Morgalad
Posts: 110
Joined: 17 January 2017, 20:46
Contact:

Re: Updating Counters after animation delay

Post 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;
			},
			
Last edited by Morgalad on 14 February 2017, 23:50, edited 1 time in total.
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Andy_K
Posts: 51
Joined: 13 February 2014, 15:59

Re: Updating Counters after animation delay

Post by Andy_K »

Great work. Just the sort of thing which would be useful in a common community code library :)
Post Reply

Return to “Developers”