I made a racetrack game. I am trying to make it scalable on mobile devices.
I was able to make it look fine when device orientation is normal (vertical):

But when I rotate the device to horizontal view, this happens: (how to zoom it out a bit )?

What would you recommend doing? I used display: none  to hide the images.
I would really appreciate any help.
Edit: I've managed to do this but the view is still too much zoomed, any ideas?
const width = 800;
const height = 600;
const pixelRatio = window.devicePixelRatio || 1;
canvas.width = width * pixelRatio;
canvas.height = height * pixelRatio;
canvas.style.width = `${width}px`;
canvas.style.height = `${height}px`;
// for sprites scaled up to retina resolution
canvas.mozImageSmoothingEnabled = false;
canvas.imageSmoothingEnabled = false;
c.scale(pixelRatio, pixelRatio);
<!DOCTYPE html>
<html lang="pl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, height=device-height">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
    <title>Canvas Story</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
        canvas {
            display: block;
        }
        body {
            margin: 0;
        } 
        #container {
            margin: 0 auto;
            width: 800px;
            height: 600px;
            overflow: hidden;
            position: relative;
            border: 1px solid #000;
            border-radius: 10px;
            margin-top: 2px;
        } 
    </style>
</head>
<body>
    <br/>
    
    <img id="obstacle" src="obstacle.png" style="display: none;" />
        <img id="bonus" src="bonus.png" style="display: none;" />
        <img id="bullet" src="bullet.png" style="display: none;" />
        <img id="car" src="car.png" style="display: none;" />
    <div id="container">
        <canvas id="ltpcanvas"></canvas>
    </div>
    <div class="circleBase" id="rotateMode" style="margin:0 auto;">
        <button id="left" onmousedown="leftKeyPressed()" onmouseup="leftKeyReleased()" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-arrow-left"></span></button>
        <button id="right" onmousedown="rightKeyPressed()" onmouseup="rightKeyReleased()" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-arrow-right"></span></button>
        <button id="middle" onclick="bulletsPush()" class="btn btn-default btn-sm"><span class="glyphicon glyphicon glyphicon-record"></span></button>
        <button id="up" onmousedown="upKeyPressed()" onmouseup="upKeyReleased()" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-arrow-up"></span></button>
        <button id="down" onmousedown="downKeyPressed()" onmouseup="downKeyReleased()" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-arrow-down"></span></button>
    </div>
    
    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="css.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="canvas.js"></script>
    
</body>
</html>
                use this in head tag:
<meta name="viewport" content="width=device-width, initial-scale=1">
The width=device-width part sets the width of the page to follow the screen-width of the device (which will vary depending on the device).
The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser.
and in animate add these:
            c.clearRect(0, 0, canvas.width, canvas.height);
            drawCanvas(boundaryLeftOffset - 2, 0,window.innerWidth, 
            window.innerHeight, 'grey');
                        Update canvas size or anything you need, in a callback for resize events of the window object:
window.addEventListener('resize', function() {
    // canvas resize, etc.
}, false);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With