Jump to content

Phaser documentation, no code examples?


BdR
 Share

Recommended Posts

I'm just getting started with Phaser and I'm making some nice progress :) Because I'm just getting started I've noticed that the documentation pages are very thorough, but unfortunately they don't contain code examples. This makes it a little difficult to see how to use the various objects and functions in a game.
 

As an example, I was trying to get the keyboard input to work so that when the player presses spacebar the game fires a bullet. So I was looking through the Phaser documentation for keyboard, and figured it had to be something with onDownCallback but didn't have any clue as to how to use it. Luckily, then I found this forum post which explains that you can also do it by using keyboard.addKey like so:

this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR).onDown.add(this.doSomething, this);

Just looking at the documenation I wouldn't have guessed that is the use of addKey. Or am I missing some clever code editor which gives hints or something? (I just use notepad++)

Link to comment
Share on other sites

Your particular example is answered here: http://www.html5gamedevs.com/topic/7405-any-key-pressed/

 

I can't speak directly for Rich but I think that given the size and scope of Phaser, one of the difficulties has been in documenting everything properly. The docs are pretty thorough as docs go, but I admit that they do lack somewhat in the code examples aspect, which is a shame because I too find learning from these easier than consulting function parameters etc.

 

The best things you can do is search the forums, check out the example projects and if all else fails ask on these very forums - there're plenty of active people, myself included, who are on every day trying to help people out. Eventually I plan to contribute code samples myself for much of Phaser's API, but currently I have other projects on the go (some Phaser related) so I guess remain vigilant until that happens! :)

Link to comment
Share on other sites

You can look at a lot of small code example written in Phaser right here: http://examples.phaser.io/ 

 
I've checked out the examples already and they are very helpful. In particular I've looked at the Tanks game for the rotating sprites. Also, I've looked at this Monster Wants Candy example for the general structure of a game, how to using game.state to move between main menu to game to game over screen etc. 
 

Thanks both, and I'll continue to search the forums whenever I need some help. :)

Link to comment
Share on other sites

Yeah we never found a good clean way of embedding actual useful code examples into the jsdocs. But we have been very very hard at work on the new Phaser web site, which I'm confident will solve a lot of these problems! Docs. examples, user comments, tutorials and live code edits all in one place. Finally :) It has been taking up a lot of my time recently, but we're getting there.

Link to comment
Share on other sites

I've found the docs to be a little lacking as well. What is there is very thorough but it's really hard to find out about all the functionality and how to use it - there's so much in Phaser that is super useful but it's often quite hidden so unless you read through everything you often won't know things exist.

 

Am looking forward to the new docs - hopefully they will help make everything much clearer (and more interactive from the sound of it).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...