smks Posted April 20, 2015 Share Posted April 20, 2015 Hey all, I have decided to make the transition from Actonscript 3 to Javascript for game development. I created a Point and Click game that I had worked on for quite some time in Actionscript. https://github.com/smks/blue-karma-as3 Now that is finished I want to rewrite it in Javascript. I came across Phaser, and it seems like the right way to go. I installed the boilerplate code with Yeoman: yo phaser-officialMy question is, I want to organize everything into its own class like structure to keep things maintainable, is this the right approach? Using the module pattern:var BlueKarma = BlueKarma || {};BlueKarma.Sprite = BlueKarma.Sprite || {};/** * Example usage: * var player = new Player(game, 100, 100, 'player'); * * @param game * @param x * @param y * @param key * @param frame * @constructor */BlueKarma.Sprite.Player = function (game, x, y, key, frame) { 'use strict'; // add a new object Phaser.Sprite as prototype of Player Phaser.Sprite.call(this, game, x, y, key, frame); // set id of Sprite this.id = 'Player'; // set anchor point of Sprite this.anchor.setTo(0, 0);}/** preload function for Player of type Sprite **/BlueKarma.Sprite.Player.prototype.preload = function() { // preload sprite // this.load.image('player', 'assets/BlueKarma/sprites/player.png');}/** create function for Player of type Sprite **/BlueKarma.Sprite.Player.prototype.create = function() { console.log("Created player"); // create sprite}/** update function for Player of type Sprite **/BlueKarma.Sprite.Player.prototype.update = function() { // update sprite}// specify the constructorBlueKarma.Sprite.Player.prototype = Object.create(Phaser.Sprite.prototype);module.exports = BlueKarma.Sprite.Player;Then when I want to use it in one of my game states: e.g. Level One:'use strict';function Menu() {}Level1.prototype = { preload: function () { var player = require('../Players/Player'); playerInstance = new player(); // or var player = new BlueKarma.Players.Player(game, 100, 100, 'player', 'player-frame'); }, create: function () { }};module.exports = Level1;Unsure as to how I can pull in the classes I need like I usually do with Actionscript. Any help would be great! Thanks,Shaun. Link to comment Share on other sites More sharing options...
Recommended Posts