Sign in to follow this  
prokopst

view/game content independent of screen resolution

Recommended Posts

Is it possible to create view where game content is independent of screen resolution in pixi.js? I mean that game content is scaled, so game appears the same on lower and higher resolution (yeah, there is an aspect ration that needs to be solved too).

 

I have found this tutorial:

http://www.html5gamedevs.com/topic/620-tutorial-handling-game-scenes-and-screen-scaling-with-pixi/

But I think it's just silly to apply scaling on all objects before render and after render to reset it. :rolleyes:

 

I checked the demos and Run Pixie Run appears to have change size of the game content to fit the screen (maybe I didn't dig in the code deep enough, but it doesn't appear to be... self describing).

Share this post


Link to post
Share on other sites

You can try something like that in your index.html:

function resize() {            var screen_height = window.innerHeight;            var screen_width = window.innerWidth;            var width = screen_width;            var height = screen_height;            if(screen_height > screen_width){                var ratio = stage.canvas.height/stage.canvas.width;                height = ratio * screen_width;            }else{                var ratio = stage.canvas.width/stage.canvas.height;                var width = screen_height * ratio;            }                        canvas.style.width = width+'px';            canvas.style.height = height+'px'; } window.addEventListener('resize', resize, false);
Also call resize() after you initialization function.

Share this post


Link to post
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.

Guest
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.