oakmac / chessboardjs

JavaScript chessboard
https://chessboardjs.com
MIT License
2k stars 406 forks source link

Change Piece color at runtime #205

Closed Astrydax closed 1 year ago

Astrydax commented 3 years ago

It seems that the piece images are only loaded at startup through a config. Would it be possible to allow choosing the images at runtime and not just startup?

blunket commented 3 years ago

You can accomplish this by using a function for the piece theme configuration instead of a string. I did it like so:

getPiece(piece) {
    return 'images/pieces/' + this.chosen_theme + '/' + piece + '.png'
}

Replace chosen_theme with whatever variable holds the pieces theme you want.

Then in your board config you set pieceTheme to the getPiece function.

Astrydax commented 1 year ago

Please close issue