benny! Posted October 7, 2013 Share Posted October 7, 2013 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! Tom W Hall 1 Quote Link to comment Share on other sites More sharing options...
Rex Rhino Posted October 10, 2013 Share Posted October 10, 2013 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. Quote Link to comment Share on other sites More sharing options...
txusludei Posted October 14, 2013 Share Posted October 14, 2013 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 [email protected] :-) Quote Link to comment Share on other sites More sharing options...
xerver Posted October 14, 2013 Share Posted October 14, 2013 Is placing a display object that contains all your children in the stage and scaling it not enough? benny! and Tom W Hall 2 Quote Link to comment Share on other sites More sharing options...
benny! Posted October 14, 2013 Author Share Posted October 14, 2013 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! Rex Rhino 1 Quote Link to comment Share on other sites More sharing options...
xerver Posted October 15, 2013 Share Posted October 15, 2013 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. Quote Link to comment Share on other sites More sharing options...
benny! Posted October 15, 2013 Author Share Posted October 15, 2013 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.