Jump to content

Runtime Dimension Changes


JAA
 Share

Recommended Posts

You set up an application element:

g_Pixi = new PIXI.Application(width, height, { backgroundColor: 0x000000 });
document.getElementById(strCanvasDiv).appendChild(g_Pixi.view);

'width' and 'height' are the dimensions of the canvas with id strCanvasDiv..

Question 1: in the object, should I send the canvas in the 'view' element? Ie,

g_Pixi = new PIXI.Application(width, height, { view: document.getElementById(strCanvasDiv), backgroundColor: 0x000000 });

But then the user decides he wants to change the dimensions of the screen (which in my code will change the dimensions of the canvas). For example, he could modify the window or even change landscape to portrait.

Question 2: What do I do to change the dimensions of the renderer to the new dimensions of the canvas so it all works still?

 

Link to comment
Share on other sites

Pass it to the view, use "g_Pixi.renderer.resize(newWidth, newHeight)" every time. Also, if you are making it for mobile and want to use "resolution" property, too, you have to understand that w/h you pass are UNMULTIPLIED, and they are "g_Pixi.screen" . Multiplied (real) pixel size in "g_Pixi.view" will equal to (newWidth * resolution, newHeight*resolution). 

There's parameter in options, "autoResize", it ensures that CSS width/height is in sync with "g_Pixi.screen", but most of devs are controlling CSS themselves. 

Link to comment
Share on other sites

Thanks guys.

[Question to Ivan at end.]

My code is now (where strCanvas is the id of the canvas, not containing div):

g_Pixi = new PIXI.Application(width, height, { view: document.getElementById(strCanvas), backgroundColor: 0x000000 });

And my adjust size code is now:

g_Pixi.renderer.autoResize = true;
g_Pixi.renderer.resize(widthDOM, heightDOM);

@Ivan, I am not sure what I should be doing about the resolution for mobiles etc.

How do I find the screen resolution, and how do I alter my code to take it into account?

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.

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

  • Recently Browsing   0 members

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