OddPotion Posted May 22, 2016 Share Posted May 22, 2016 Hi everyone, first time posting but I've been poking around for a bit. =P Lately I've been working with a top down action shooter and I'm trying to determine how best to do different characters that the player can select from before play. Each Character would have different abilities for example a Fighter type character may have Axe Throw and Shield Bash abilities and a Wizard type character might have Fire Bolt and Lightning Strike as two abilities. My question is would it be best to create separate objects from Phaser to contain these character 'blue prints' and have this Character class contain a Phaser.Sprite? var Character = function(data){ this.sprite = data.sprite; }; var fighter = new Character(fighter_data); var wizard = new Character(wizard_data); Or then maybe even extending Character into separate Fighter/Wizard classes instead. var Character = function(data){ this.sprite = data.sprite; }; var Fighter = function(data){ Character.call(data); }; Fighter.prototype = Object.create(Character.prototype); Fighter.prototype.constructor = Character; var player = new Fighter(data); Or would it be ok to either extend Phaser.Sprite into a Character class(and then probably extend into Fighter class) or just create a Phaser.Sprite and pump a bunch of random variables into it? var Character = function(game, key){ Phaser.Sprite.call(this, game, 0, 0, key); this.health = 100; this.maxHealth = 100; this.speed = 4; }; Character.prototype = Object.create(Phaser.Sprite); Character.prototype.constructor = Character; Character.prototype.useAbility = function(){ // } /* OR */ var player = game.add.sprite(start.x, start.y, 'fighter_sprite'); player.health = 100; player.maxHealth = 100; player.speed = 4; player.useAbility = function(){ // } Sorry if this is hard to follow. It's late in these here parts. haha Link to comment Share on other sites More sharing options...
Recommended Posts