Page 1 of 1

Animation glitch in removeFromStock() when removing more than one element at a time

Posted: 20 June 2020, 20:50
by Brainchild
I'm using a Stock component to hold two gold cubes in the play area. When a player claims gold, the cubes slide from the play area to the player panel, then disappear. I didn't write any animation code, I'm just using the built-in stock.removeFromStock() like so:

Code: Select all

        awardGoldToPlayer: function(player_id, gold, from_stock_index)
        {
            let gold_element = $("gold_" + player_id);

            if (from_stock_index != null)
                for (let i = 0; i < gold; i++)
                    this.goldZones[from_stock_index].removeFromStock(0, gold_element);

            gold_element.innerHTML = toint(gold_element.innerHTML) + gold;
        },
If the player only claims one gold cube, it slides to the player panel and the remaining gold cube centers itself in the zone. However, if the player claims both of the gold cubes in the zone, they both animate as expected to the player panel, but then an animation plays in the zone of a ghost cube sliding to the center, even though there are no cubes left there.

Here's a gif of the glitch:

https://imgur.com/a/iWGBuGp

Is it a bug or am I mis-using the Stock component?

Re: Animation glitch in removeFromStock() when removing more than one element at a time

Posted: 20 June 2020, 23:18
by hersh
Depending on the situation you may need to clone the item before animation.

See http://en.doc.boardgamearena.com/Stock at the bottom there are different situations described. Yours sounds like C, from stock item to non-stock item.

Re: Animation glitch in removeFromStock() when removing more than one element at a time

Posted: 21 June 2020, 08:22
by Een
Brainchild wrote: 20 June 2020, 20:50 Is it a bug or am I mis-using the Stock component?
That's a glitch of the stock component when looping to remove several items.
It comes from the fact that the updateDisplay() method is called on each removeFromStock() call.

A 'noupdate' parameter has been added some months ago to be able to do something like this:

Code: Select all

for( var i in ids )
            {
               myStock.removeFromStockById( ids[i], to, true );
            }
            myStock.updateDisplay();
Which works as expected.

I noticed that the 'noupdate' parameter was only on removeFromStockById(), and added it to removeFromStock() too. This will be in the next release.

Re: Animation glitch in removeFromStock() when removing more than one element at a time

Posted: 21 June 2020, 09:40
by Brainchild
Een wrote: 21 June 2020, 08:22 I noticed that the 'noupdate' parameter was only on removeFromStockById(), and added it to removeFromStock() too. This will be in the next release.
Wonderful, thanks!