chessboardjs icon indicating copy to clipboard operation
chessboardjs copied to clipboard

How can I change the piece theme after the board is created?

Open frazereastman opened this issue 4 years ago • 1 comments

I am creating a chess opening trainer and want to know how I can change the piece theme after the board has been generated using the config settings? Thank you in advance.

frazereastman avatar Apr 13 '21 15:04 frazereastman

Hi,

simply put the png files of your theme in a subfolder. They must be named bB.png, bK.png,...,wB.png, wK.png and so on. Then trigger your board and set the correct folder path in the settings object.

let pieceSetup ....(some script to get the folder name)

let board = Chessboard('yourBoardID', {
  pieceTheme: `[path to your themes folder]/${pieceSetup}/{piece}.png`,
  // other settings...
});

Variable "pieceSetup" is the subfolder name with your png files of the pieces. As this is in a string literal you can change it with your script.

greets, hc

hcgreier avatar Oct 22 '22 21:10 hcgreier