sergil Posted November 14, 2013 Share Posted November 14, 2013 Anyone has experience using cocoonjs launcher? If I run the helloPhaser example it works well on android cocoonjs launcher but when I run a little game that I made with Phaser nothing is displayed. I put console.log messages in every script and I can see that the launcher only executes the index.html code (it prints the index log message)? Here I put the body part of my index.html<body> <script type="text/javascript"> function boot() { console.log('index'); // No parameters given, which means no default state is created or started var game = new Phaser.Game(640, 960, Phaser.AUTO); game.state.add('boot' , TestGame.Boot, true); game.state.add('preloader' , TestGame.Preloader); game.state.add('mainmenu' , TestGame.MainMenu); game.state.add('game' , TestGame.Game); } window.onload = function () { boot(); } </script> </body>In the boot script I used console.log messages but nothing is printed... could be the problems with working with states??? In my desktop all if going well. Thanks in advance Link to comment Share on other sites More sharing options...
jcs Posted November 14, 2013 Share Posted November 14, 2013 I played with the cocoon launcher for a few minutes... I was able my game to come up in the launcher, but the size of the canvas was tiny (not scaled like it is in a browser), and my on-screen touch controls were scaled differently so that it was difficult (okay, probably impossible) to actually play. it did seem to be drawing correctly however. at some point I plan on getting back to it, but it's been low on my priority list. IIRC, I had to muck about with the html file to make it happy (removed some attributes from the div where the canvas lives, I think) Link to comment Share on other sites More sharing options...
rich Posted November 15, 2013 Share Posted November 15, 2013 I suspect the issue is scaling. I installed the CocoonJS launcher last week so will experiment on how to get it running, once solved I'll post a message up on the forum. Link to comment Share on other sites More sharing options...
sergil Posted November 15, 2013 Author Share Posted November 15, 2013 Thanks rich... A think that I could see is that messages in js files (boot, main,...) don't show in cocoonjs launcher... If you need help with cocoonjs launcher or want my code to test tell me ok? Link to comment Share on other sites More sharing options...
dTb Posted November 19, 2013 Share Posted November 19, 2013 @Sergil: sorry, I am on my iPad so I cannot check and be 100% sure of what I am going to say.. but let's say 95% in Cocoonjs (or Ejecta) the window object is simulated, there is no DOM.I don't think window.onload is supported and it's just not required at all for sure.Just put boot(); outside of any condition.On my games I am using this : // ------------------------- // Trigger the init // ------------------------- if (typeof window.onload !== 'undefined') { // if we are in a regular browser window.onload = init; } else { // we are in something like ejecta.. no need to wait for start init(); }If you really want a listner, when we check cocoonjs api/implementation ( http://wiki.ludei.com/cocoonjs:featurelist#window ), the window.addEventListener('load', init, false); seems to be supported. Link to comment Share on other sites More sharing options...
dTb Posted November 19, 2013 Share Posted November 19, 2013 @jcs: on my side I just create a canvas (or in this case a screencanvas to get the hardware acceleration) and set the width and height to window.innerWidth and window.innerHeight to get it full screen.edit: just re-read your post and saw you had to tweak a div and a canvas: in Cocoonjs or Ejecta there is no DOM and no div, just a canvas. The best practice in my opinion is to have the body completly empty and to append a canvas/screencanvas from the javascript, or to have this canvas/screencanvas tag only. Link to comment Share on other sites More sharing options...
jcs Posted November 19, 2013 Share Posted November 19, 2013 my assumption from reading the cocoon docs was that the div would be ignored, but perhaps not.in any case, I'll try it with an empty canvas when I get a chance. thnx Link to comment Share on other sites More sharing options...
sergil Posted November 19, 2013 Author Share Posted November 19, 2013 I will try Link to comment Share on other sites More sharing options...
sergil Posted November 19, 2013 Author Share Posted November 19, 2013 I tested with your code and it doesn't work... in desktop works well but with cocoonjs it turns the screen black, and doesn't show the sprites without your code and calling directly phaser it launches in cocoonjs and in desktop (I think I don't need to use window.onload because there isn't elements to load) , but in cocoonjs now it's throwing a error. The code in index.html is this: <body> <script type="text/javascript"> console.log('index'); // No parameters given, which means no default state is created or started var game = new Phaser.Game(640, 960, Phaser.AUTO); game.state.add('boot' , TestGame.Boot, true); game.state.add('preloader' , TestGame.Preloader); game.state.add('mainmenu' , TestGame.MainMenu); game.state.add('game' , TestGame.Game); </script> </body>the error is :Javascript Exception (Tag: 'load'):Error:Phaser.Loader. Invalid XML given at Object.Phaser.Loader.xmlLoadComplete (js/phaser.js:30753:10) at XMLHttpRequest._xhr.onload(js/phaser.js:30609:20)I think It crashes in the line of my preloader.js file (for my testings I used asset files from phaser examples):this.load.bitmapFont('desyrel', 'assets/fonts/desyrel.png', 'assets/fonts/desyrel.xml'); Link to comment Share on other sites More sharing options...
dTb Posted November 20, 2013 Share Posted November 20, 2013 Ok, now I guess it's really a Phaser + CocoonJs issue. hints: - CocoonJs XMLhttprequest implementation is limited. You can try to put console logs inside Phaser to see what's inside the XHR object. I would say inside the xmlLoadComplete method, a first step would be to print the keys and see what's inside.Something like :for (var k in this._xhr) { if (this._xhr.hasOwnProperty(k)) { // splitting console logs for readability in cocoonjs app console.log(k + ':'); console.log(this._xhr[k]); }}- I don't know if their implementation is working for local files, maybe it's working only for http/https requests ? - One good thing (unrelated with your problem but worth to be mentioned I think) with this XHR: there is no cross domain security issues like in browsers and you can retrieve anything from anywhere, get image data etc.. without problem Link to comment Share on other sites More sharing options...
GregP Posted November 20, 2013 Share Posted November 20, 2013 Hi sergil,I was playing with similar problem recently.The reason your code wasn't launching properly before is the way how Phaser's Game class is implemented.You were creating new Game on window's load event, in this case Phaser is checking for document.readyState value and expects it to equal 'complete' or 'interactive'.And since these states aren't available in CocoonJS, it registers another load/DOMContentLoaded event callbacks. (lines 236 - 244 inside src/core/Game.js)The way I solved this issue was overriding readyState value inside my onload handler.Hope it helps ^^ Link to comment Share on other sites More sharing options...
sergil Posted November 20, 2013 Author Share Posted November 20, 2013 If I quit the bitmapFont in my game the game, In cocoonjs it seems to work, but it is bad resized as Rich said. The button touch doesn't work very well, because it seems that the position of the touch is different from the painted button position. If I touch where the button has to be painted it works, but If I touch the painted button it doesn'tAnother thing is that the touch I have in my extended sprite doesn't work.this.events.onInputDown.add(this.mouseDownBubble, this);I included console.log in the mouseDownBubble function, but the messages are never printed (in desktop all is working well and the messages are correctly printed) Link to comment Share on other sites More sharing options...
rich Posted November 20, 2013 Share Posted November 20, 2013 sergil - have you tried setting the game size to match the window.innerWidth/height? I expect Cocoon doesn't want the canvas scaled at all. Link to comment Share on other sites More sharing options...
sergil Posted November 20, 2013 Author Share Posted November 20, 2013 Using var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO);fix the problem with scale and position... now there are only two errors: 1. Loading bitmapFont from an XML2. the touch problem over my extended sprites using this.events.onInputDown.add(this.mouseDownBubble, this); Link to comment Share on other sites More sharing options...
onefatman Posted August 15, 2014 Share Posted August 15, 2014 i know this is old as hell but did anyone ever work out how to get a touch event on a sprite in cocoon js? I can implemene a scaling offset on generic touch events but not sure how that affects events directly attached to sprites, etc . . . my code:this.playButton = this.add.sprite(140, 403, 'titlepage');this.playButton.inputEnabled = true;this.playButton.events.onInputDown.add(this.onMenuDown, this); Link to comment Share on other sites More sharing options...
Recommended Posts