Jump to content

engine.getAspectRatio(); does not work until resize?


Pryme8
 Share

Recommended Posts

https://pryme8.github.io/TileMaster/editor/

So If you go ahead and create a new project, then add a stage, then add a plane.  You will see the bug.  Notice you see no change and if you have the console open you will see NAN outputs for the aspectRatio.

Now the second you resize the scene it fixes this and starts correctly outputting the aspectRatio
https://github.com/Pryme8/TileMaster/blob/gh-pages/editor/js/tm.editor.js#L394

Is where the function is used and
https://github.com/Pryme8/TileMaster/blob/gh-pages/editor/js/tm.editor.js#L34
Is where it fires from... the odd part is technically I fire the resize manually before anything happens so shouldn't this work?

 

Link to comment
Share on other sites

for the time being i replaced the line:
var aspectRatio = engine.getAspectRatio(c);
with:

var rect = engine.getRenderingCanvasClientRect();
var aspectRatio = rect.width/rect.height;

and it seems to be adequate as a work around so no rush on this problem... but I am kinda wondering what the root cause of it is still.

*EDIT*
that did not fix it actually, but I made a work around.

Link to comment
Share on other sites

  • 4 weeks later...

Im bringing this topic back... there is something odd in this behavior.

So basically my scenes are broken until I fire a engine.resize();

I am thinking this is because the canvas elements are set to display:none initially and are enabled later.  

But here is where things get odd, if I do a engine resize prior to the display of the canvas its like nothing effectively happens.

I am forced then to do this:
https://github.com/Pryme8/TileMaster/blob/gh-pages/editor/js/tm.editor.js#L104
which seem really kinda dumb... I mean it works but if I nerf these lines when you select a tile it displays it in the preview block like its a single pxl from the center of the tile is the only one that displays over the whole canvas.

But if I include these lines everything "works"
http://pryme8.github.io/TileMaster/editor

I am focused on the sheetEditor part if your looking for the working example.

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