Giter VIP home page Giter VIP logo

meteor-phaser's Introduction

meteor-phaser

Project skeleton for developing Phaser games with Meteor.

How to use

You need the PhaserIO package from Atmosphere. Follow these steps:

  1. Clone the PhaserIO project from github into the packages folder.
  2. Rename the folder from meteor-phaser to phaserio
  3. Go inside the phaserio folder and run git submodule update --init.
    • It will now download the latest Phaser to the phaserio folder.

Running the app

If all goes as planned, you should be able to start the app by running

meteor

Dependencies

meteor-phaser uses

Project Layout

Most of the magic happens in the client folder. Assets except for CSS files are stored in public.

client/
	game/
		sprites/
		states/
			BootState.coffe        # Loads the Preload-Sprite and configues game/screen
			PreloaderState.coffee  # Loads all assets and displays Preload-Sprite
			MainMenuState.coffee   # Menu, just shows a sprite for now
			InGameState.coffee     # Code for the game can go here
		game.coffee	 			   # Starts the Game

	stylesheets/
		phaser-meteor.css

	game.html					   # Loads the game through a helper defined in game.coffee
	header.html					   # Title of the page currently defined here
	phaser-meteor.html			   # Glues the templates together and is the current index page.

In Depth

Let's take a look at phaser-meteor.html It defines the rough site layout and has two Handlebars templates to do so, header, which layouts everything above the game, and game, which is the game itself.

<head>
	<title>phaser-meteor</title>
</head>

<body>
	{{> header}}

	{{> game}}

	{{> footer}}
</body>

The header template is not interesting at the moment, and the code is straightforward, so let's skip to the game template. It has an id instead of a class because it will serve as the parent for the canvas.

<template name="game">
	<div id="game">
		{{game}}
	</div>
</template>

game.coffee defines the template helper for this template. Feel free to adjust the size, convert it to full screen, or even make the game responsive (check out this interesting article from mobi.fm). The explicit return is so we don't have any code output to our browser window.

Template.game.game = ->
	game = new Phaser.Game(800, 600, Phaser.AUTO, "game")
	game.state.add "Boot", new BootState, false
	game.state.add "Preloader", new PreloaderState, false
	game.state.add "MainMenu", new MainMenuState, false
	game.state.add "InGame", new InGameState, false

	game.state.start "Boot"

	return

Aside: I'm an HTML and CSS noob, there's no other way of putting it. I did, however, manage to center all of the elements and you can review or throw away the code here:

.centered {
	padding-left: 0;
	padding-right: 0;
	margin-left: auto;
	margin-right: auto;
	width: 1024px;
	text-align: center;
}

canvas {
	padding-left: 0;
	padding-right: 0;
	margin-left: auto;
	margin-right: auto;
	display: block;
	width: 800px;
}

.footer {
	width: 800px;
}

.footer pre {
	margin-left: 0;
	margin-right: 0;
	text-align: left;
}

Ending Remarks

If you want, you can install an HTML templating engine such as Jade that works with Handlebars. The Atmosphere plugin page for Meteor and Meteorite has just such a plugin. Stylus, Less and SASS are supported by Meteor directly.

For how I knew how to install Meteorite packages under windows, see this helpful post by Tom Coleman.

For any remarks, criticisms or suggestions, feel free to email me at [email protected]

meteor-phaser's People

Contributors

soulbeaver avatar ravinderpal avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.