MikeHart Posted September 4, 2013 Share Posted September 4, 2013 Hi folks, I am a total newbie regarding Phaser and not much more when it comes to javascript. In the examples, I basically can't find an example how to setup a simple project with it. Take the Minigame "f1.js", how does one get to run this script? Can someone show me a simple setup, maybe containing an index.html file, its css file and the javascript file with a small example? that could get me started. ThanksMichael Link to comment Share on other sites More sharing options...
rich Posted September 4, 2013 Share Posted September 4, 2013 I'm in the middle of writing one at the moment! It's for the new JS build, but it's super easy to get started with I promise If you want to be a proof reader / sanity check for me then drop me an email ([email protected]) Link to comment Share on other sites More sharing options...
MikeHart Posted September 4, 2013 Author Share Posted September 4, 2013 Email send :-) Link to comment Share on other sites More sharing options...
rich Posted September 6, 2013 Share Posted September 6, 2013 Thanks for your email (and to the others who also contacted me!). I will send you all a link to proof it when I'm ready, which should be early next week. Link to comment Share on other sites More sharing options...
Mmarzex Posted September 14, 2013 Share Posted September 14, 2013 Is there any sort of doc like this available yet? Link to comment Share on other sites More sharing options...
rich Posted September 14, 2013 Share Posted September 14, 2013 There's a getting started guide on the web site (http://www.phaser.io) and lots of examples in the examples folder. We'll release API docs and more tutorials soon, but in the meantime post to the forum if you've questions. Link to comment Share on other sites More sharing options...
Mmarzex Posted September 14, 2013 Share Posted September 14, 2013 Sorry, I was more wondering if you had any tutorial or example about not having the javascript in the html but instead in separate .js files. Link to comment Share on other sites More sharing options...
Travis Posted September 14, 2013 Share Posted September 14, 2013 Hi Mmarzex, I think I can help you out Here's some simple steps you can use to create a template for starting a new project with multiple files and no inline script.This tutorial uses the "Hello Phaser" folder which you can find in the phaser-master/Docs directory. 1) Set up a project folder in your local server's /www or /htdocs folder. Set it up however you like, I personally made bin, lib, and src folders for holding assets, libraries (phaser in this case) and source code, respectively. 2) Copy the logo.png file, index.html file, and phaser-min.js file into your project folder. Put them in their proper directories. Here's what mine looks like: 3) Now create a new javascript file in your source directory, I name mine game.js. 4) Open your index.html file, and copy the content of the inline <script> into your game.js file. 5) If logo.png and index.html are not in the same folder, change the line game.load.image('logo', 'logo.png') to game.load.image('logo', '(YOUR_DIRECTORY)/logo.png') 6) Delete the first and last lines of game.js Your game.js should now look something like this: var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload() { game.load.image('logo', 'bin/logo.png'); } var logo; function create() { logo = game.add.sprite(0, 0, 'logo'); } function update() { }7) Now go back to your index.html file and delete the inline <script> code as well as all of the <body> code. Phaser will automatically create a <body> and <canvas> element for you, so you don't need to worry about that. 8) If phaser-min.js is in a different folder than index.html, change the script src= to your proper directory. 9) Make sure to add your game.js script in, for me it was <script src="src/game.js"></script> Your index.html should look like this:<!DOCTYPE HTML><html><head> <title>phaser - hello world</title> <script src="lib/phaser-min.js"></script> <script src="src/game.js"></script></head></html>10) Now open localhost/(PROJECT_FOLDER_NAME) and if you set up everything correctly, it should work! I hope this helps! -Travis Link to comment Share on other sites More sharing options...
Mmarzex Posted September 14, 2013 Share Posted September 14, 2013 Cool, thanks. That makes sense. I guess for some reason I was thinking I needed to do some sort of require statement or something in the other js file. Way too much node stuff lately, just need to get it to work with webstorm now for the auto complete. Link to comment Share on other sites More sharing options...
Travis Posted September 14, 2013 Share Posted September 14, 2013 Yep. An interesting thing, and someone can correct me if I'm wrong here, is that you can actually share global variables across multiple .js files. However, if you have inline script, the global variables in your outside files won't be read. Link to comment Share on other sites More sharing options...
misko Posted September 14, 2013 Share Posted September 14, 2013 And what about states? In Flixel we had FlxState, how do you handle that in HTML5 version? I'm new to HTML5 games from Flash... Thanks,Josip Link to comment Share on other sites More sharing options...
Travis Posted September 15, 2013 Share Posted September 15, 2013 Hey Josip, I haven't tinkered with States yet in Phaser, but you can find good info right here:https://github.com/photonstorm/phaser/blob/master/src/core/State.jsand here:https://github.com/photonstorm/phaser/blob/master/src/core/StateManager.js Link to comment Share on other sites More sharing options...
rich Posted September 15, 2013 Share Posted September 15, 2013 misko - have a look in the repo in this folder: wip/examples/state You'll find a 3 state set-up (Preloader, MainMenu, Game) swapping between them all happily, one JS file per state. Use that as a basis for rolling your own. mikehamil10 1 Link to comment Share on other sites More sharing options...
misko Posted September 15, 2013 Share Posted September 15, 2013 Thanks, it's really nice and easy. Phaser is awesome. Link to comment Share on other sites More sharing options...
mikehamil10 Posted September 17, 2013 Share Posted September 17, 2013 That state example was extremely useful, almost imperative for creating anything in Phaser beyond trivial examples. Hopefully it will be ready to be moved out of WIP and into the mainstream examples soon because I think it will help a lot of people out... Link to comment Share on other sites More sharing options...
mikehamil10 Posted September 17, 2013 Share Posted September 17, 2013 Actually, just updating the path of the assets to look in the /examples/assets folder makes the state example work perfectly. Is there any reason why it couldn't be moved out of wip as-is? MrJerB 1 Link to comment Share on other sites More sharing options...
Recommended Posts