0

I am really new to craftyjs and I wrote a new game that created a full screen canvas. The game creates instance of board that draw a board with size of boardSize X boardSize:

var Game = {
        start: function() {
            Crafty.init();

            var boardSize = Math.min(window.innerWidth, window.innerHeight);
            Crafty.e('Board').board(boardSize);
        }
    };

I would like the board to be changed on resize according to the new window size. How can I do that?

Naor
  • 23,465
  • 48
  • 152
  • 268

1 Answers1

1

You could subscribe on window resize event and change the Board component size accordingly. Example:

window.onresize = function() {
  var boardSize = Math.min(window.innerWidth, window.innerHeight);
  Crafty(Crafty('Board')[0]).board(boardSize);
};
Giovanni Cappellotto
  • 4,597
  • 1
  • 30
  • 33