Jump to content

CocoonJS WebGLRenderer Scaling Question


benny!
 Share

Recommended Posts

Hi,

 

I did my first tests with Pixi,js and CocoonJS. Basically, it seems to work. However, I have got the following issue.

 

Example Code:

<html>    <head>        <title></title>        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">        <style type="text/css">body { margin: 0px; }</style> <!-- Android fix -->    </head>    <body>        <script src="js/pixi.js"></script>        <script type="text/javascript">            window.onload = function() {                var canvas = document.createElement(navigator.isCocoonJS ? 'screencanvas' : 'canvas');                       canvas.style.cssText="idtkscale:ScaleAspectFill;";                canvas.width= 320;                canvas.height= 480;                document.body.appendChild(canvas);                var stage = new PIXI.Stage(0x66FF99);                // Does scale                //var renderer = new PIXI.CanvasRenderer(320, 480, canvas);                // Does not scale                var renderer = new PIXI.WebGLRenderer(320, 480, canvas);	                                requestAnimFrame( animate );                var bunny = PIXI.Sprite.fromImage("bunny.png");                bunny.anchor.x = 0.5;                bunny.anchor.y = 0.5;                bunny.position.x = 160;                bunny.position.y = 240;                stage.addChild(bunny);                function animate() {                    requestAnimFrame( animate );                    bunny.rotation += 0.1;                    renderer.render(stage);                }                    };        </script>    </body></html>

Using the CanvasRenderer - CocoonJS scales up correctly.

 

Using the WebGLRenderer - CocoonJS does not scale up at all.

 

Maybe this is a CocoonJS issue - not quite sure. Is there's something I can do with Pixi to solve this? Like modifying the viewport or something like this? Referring to CocoonJS WebGL examples - they are always setting the dimension of the canvas to the windows.innerWidth/innerHeight.

 

Any help appreciated.

Best,

benny!

Link to comment
Share on other sites

I was having the same problem - I am using Phaser (which uses Pixi as it's renderer).

 

You can get things to run using the entire canvas using windows.innerWidth/innerHeight. The problem is that it will not be scaled. It should let you use 320x480, and the canvas should take up the entire screen... however, if you use windows.innerWidth/innerHeight and you draw a 320x480 image, it will appear as a tiny graphic instead of scaled up.

Link to comment
Share on other sites

Good call - that does the trick:

<html>    <head>        <title></title>        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">        <style type="text/css">body { margin: 0px; }</style> <!-- Android fix -->    </head>    <body>        <script src="js/libs/pixi.js"></script>        <script type="text/javascript">            window.onload = function() {                var canvas = document.createElement(navigator.isCocoonJS ? 'screencanvas' : 'canvas'),                    appWidth = 320,                    appHeight = 480;                canvas.style.cssText="idtkscale:ScaleAspectFill;";                canvas.width = window.innerWidth;                canvas.height = window.innerHeight;                                document.body.appendChild(canvas);                var stage = new PIXI.Stage(0x66FF99);                // Does scale                //var renderer = new PIXI.CanvasRenderer(320, 480, canvas);                // Does not scale                var renderer = new PIXI.WebGLRenderer(window.innerWidth, window.innerHeight, canvas);	                                requestAnimFrame( animate );                var bunny = PIXI.Sprite.fromImage("bunny.png");                bunny.anchor.x = 0.5;                bunny.anchor.y = 0.5;                bunny.position.x = appWidth / 2;                bunny.position.y = appHeight / 2;                var scaler = new PIXI.DisplayObjectContainer();                scaler.addChild( bunny );                scaler.scale.x = window.innerWidth / appWidth;                scaler.scale.y = window.innerHeight / appHeight;                                stage.addChild( scaler );                function animate() {                    requestAnimFrame( animate );                    bunny.rotation += 0.1;                    renderer.render(stage);                }                    };        </script>    </body></html>

Thanks!

Link to comment
Share on other sites

Not a problem, scale is already a point object so all you need to do is:

scaler.scale.x = window.innerWidth / appWidth;scaler.scale.y = window.innerHeight / appHeight;

No need to create a new point object.

 

Valid point. Code above updated. Thanks!

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