Jump to content

Fixed "Camera" with Resizing


Recommended Posts

Hey guys, I'm brand new to PixiJS and have an issue that i can't seem to figure out. I'm working on a real time multiplayer game where there is a larger map ~3200 x 3200 and players are free to roam. However I want each players "camera" to only show a certain number of pixels so that someone with a large screen wont have an advantage over someone with a small screen. All the game simulation is handled on the server side. I know how to setup an on resize handler I'm just struggling with which values to update. I was able to fudge this with plain javascript like so: (I only every want to show 640x 360 pixels)

const setCanvasSize = () => {
    console.log('Resizing canvas');
    CANVAS_WIDTH = window.innerWidth;
    CANVAS_HEIGHT = window.innerHeight;

    const ratio = 16 / 9;
    if (CANVAS_HEIGHT < CANVAS_WIDTH / ratio) {
    } else {

    canvas.width = 640;
    canvas.height = 360;

    canvas.style.width = `${CANVAS_WIDTH}px`;
    canvas.style.height = `${CANVAS_HEIGHT}px`;

And now I need to replicate a similar behavior but am having some trouble.


Desired effect is like so: this is a screen from my hacky version.1204633891_ScreenShot2020-07-29at4_46_26PM.thumb.png.0d2835765e96566a068f8b214b566714.png.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...