sergil

cocoonjs launcher

Recommended Posts

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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites
dTb    2

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

Share this post


Link to post
Share on other sites
dTb    2

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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');

Share this post


Link to post
Share on other sites
dTb    2

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 ;)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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't

Another 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)

Share this post


Link to post
Share on other sites

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 XML

2. the touch problem over my extended sprites using 

this.events.onInputDown.add(this.mouseDownBubble, this);

Share this post


Link to post
Share on other sites

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);

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


  • Recently Browsing   0 members

    No registered users viewing this page.