Mixing stock items

Game development with Board Game Arena Studio
Post Reply
User avatar
Brosseleir
Posts: 2
Joined: 08 April 2020, 12:09

Mixing stock items

Post by Brosseleir »

Hi,

I have a game consisting out of two types of cards, so I defined them as separate tables and they both use a different image source (one has 14 images per row, the other only 11 images per row). On the JS side I have created two stock elements, load the cards and visually present them on the screen as two separate sets.

During the game however, the cards of one set allow you to acquire cards of the other set, so I would like to migrate cards from one stock to the other. I did this with set1.addToStockWithId and set2.removeFromStockById, and I can see a card shift in, but visually the added card uses the image of set1 instead of set2.

Is there a way to make sure it remains using the correct image, or do I need a different setup so they either use the same image?

I'm experimenting with zones as we speak, so maybe that will help, but would appreciate any input as this is my first game.

Thanks a lot!
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Mixing stock items

Post by RicardoRix »

so the card you're moving, does it get setup in both different stock types?

a stock can only show cards of the type it got setup with.

I think for situation B, moving from 1 stock to another, it assumes that both stocks are setup identically. It might work as you're trying, but the card would need to exist in the setup for each stock (and have the same type(?)).
User avatar
Brosseleir
Posts: 2
Joined: 08 April 2020, 12:09

Re: Mixing stock items

Post by Brosseleir »

No, the cards of set1 are completely different from the cards in set2. E.g. set 1 are all yellow cards, set 2 are all red cards. You start with x yellow cards, but during the game your hand also gains red cards. This will then be able to play an action by selecting a yellow and a red card from your hand together, so it would be great if they can be combined in 1 stock that represents the hand as both yellow and red cards have certain values so it's logical to see them together and organised based on their weight.
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Mixing stock items

Post by RicardoRix »

I can't confirm this works with 2 different images. I never tried that.
You'll have to add ALL the different types, when you do this:
this.playerHand.addItemType( card_type_id, card_type_id, g_gamethemeurl+'img/cards.jpg', card_type_id );
you can't display a type if you haven't set it up.

If that doesn't work you'll either need to combine both images, or do something fancy with the onItemCreate().
User avatar
LeSteffen
Posts: 77
Joined: 13 July 2020, 15:32

Re: Mixing stock items

Post by LeSteffen »

Hi, you can mix source images when creating a stock. Here's an example from an unreleased game:

Code: Select all

      stock.addItemType(0, 0, g_gamethemeurl + "img/Cardback.jpg", 0);
      for (let i = 1; i <= 16; i++) {
        stock.addItemType(i, i, g_gamethemeurl + "img/CardsRed.jpg", i - 1);
      }
      for (let i = 17; i <= 32; i++) {
        stock.addItemType(i, i, g_gamethemeurl + "img/CardsPurple.jpg", i - 1 * 16 - 1);
      }
      for (let i = 33; i <= 48; i++) {
        stock.addItemType(i, i, g_gamethemeurl + "img/CardsWhite.jpg", i - 2 * 16 - 1);
      }
      
If using multiple spritesheets and not all are needed at the beginning of the game, you should enable lazy loading like so in the constructor:

Code: Select all

      this.dontPreloadImage("Cardback.jpg");
      this.dontPreloadImage("CardsRed.jpg");
      this.dontPreloadImage("CardsPurple.jpg");
      this.dontPreloadImage("CardsWhite.jpg");
Post Reply

Return to “Developers”