A
A
Afafks1231321321652020-04-22 14:55:03
JavaScript
Afafks123132132165, 2020-04-22 14:55:03

How to make canvas stretch?

How to make the canvas stretch and all the elements on it too? That is, how in io games in them the game adapts to the monitor. How to do the same? What would be not only the canvas but also the pictures? And the interface elements?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-04-22
@Seasle

const resize = () => {
    [canvas.width, canvas.height] = [innerWidth, innerHeight];
};

const init = () => {
    resize();
};

window.addEventListener('DOMContentLoaded', init);
window.addEventListener('resize', resize);

Interface elements are not drawn on canvas, they are typeset and simply displayed on top.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question