Jump to content

Starting with Phaser and Javascript


Paul-Andre
 Share

Recommended Posts

Oh, please forgive me if I'm missing something so obvious here. I wish to use Phaser from Javascript and I don't know where to start, and since there is no API documentation, I'm completely lost. The test suit is something, but there are multiple things that I don't really get.

For example, if I'd like to create a TileMap and populate it grammatically, what should I do?

Also, are there some complete game examples or tutorials in Javascript that I could play with? Everything I find seems to be for Typescript.

Link to comment
Share on other sites

You're not missing anything, I'm afraid the content you're after just doesn't really exist yet. I promise as soon as I'm over my 1.0 release issues that I'll be doing tutorials like crazy (in both JS and TS). In the meantime if you've any specific questions do ask them here and I can help.

Link to comment
Share on other sites

You would prepare your map data in a string that is comma separated.

 

Then create a new Phaser.Tilemap object. For the mapData parameter give it the string you made, and for the format parameter give it the type of Tilemap.FORMAT_CSV.

 

How you randomise that data is up to you. The string should be split on a newline: "\n", i.e.:

 

var data = "1,1,1,1

1,0,0,1

1,0,0,1

1,1,1,1";

 

Or: var data = "1,1,1,1\n1,0,0,1\n1,0,0,1\n1,1,1,1";

Link to comment
Share on other sites

createTilemap doesn't need you to pass a reference to the Phaser.Game object in, because it already knows about it and uses it. It also adds the tilemap to the display automatically. So if you just wanted to extract data from a map and not actually display it (i.e. use it for collision) then you'd create a new Tilemap object instead.

Link to comment
Share on other sites

A load of zeros. Each tile needs to know how to visually represent itself in-game, even if that's "nothing". You can manipulate the grid data easily post instantiation. But it really is something you'd want to get sorted up front, and not keep changing dimensions dynamically.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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