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

Game development with Board Game Arena Studio
Post Reply
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

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

Post 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?
User avatar
hersh
Posts: 76
Joined: 12 December 2013, 23:49

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

Post 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.
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

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

Post 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.
User avatar
Brainchild
Posts: 71
Joined: 31 January 2014, 19:42

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

Post 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!
Post Reply

Return to “Developers”