Sign in to follow this  
benny!

CocoonJS WebGLRenderer Scaling Question

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!

Share this post


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

Share this post


Link to post
Share on other sites

We provide the screen size, but we can't do the canvas transformations to the environment. You know, the WebGL renderer works in 3D ;-)

 

I wish you could ask Pixi developers to implement this transformation when the renderer is set to WebGL.

 

Any problem /bug / injuries /marriage offers can be sent to devsupport@ludei.com :-)

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.