Search the Community

Showing results for tags 'extended object'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Platform
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. How do extended object's prototype functions fit in with the current state's functions? For example: Creature = function(game, x, y){ Phaser.Sprite.call(this, game, x, y, 'mob'); game.add.existing(this); this.enableBody = true; } }; Creature.prototype = Object.create(Phaser.Sprite.prototype); Creature.prototype.constructor = Creature; and var world = { create: function(){ // Test dummy dummy = new Creature(this, 200, 200); dummy.body.static = true; } }; work, but Creature = function(game, x, y){ Phaser.Sprite.call(this, game, x, y, 'mob'); } }; Creature.prototype = Object.create(Phaser.Sprite.prototype); Creature.prototype.constructor = Creature; Creature.prototype.create = function(){ game.add.existing(this); this.enableBody = true; }; and var world = { create: function(){ // Test dummy dummy = new Creature(this, 200, 200); dummy.body.static = true; } }; return "Uncaught TypeError: Cannot set property 'static' of null" From what I read in the extending sprites examples, the prototype functions are supposed to be automatically called in the given state. Am I missing something about scope or is there some timing involved? I was wondering if i could cut down on code if i did something like // Creature constructor Creature = function(game, x, y, alignment){ if(alignment === 'good'){ Phaser.Sprite.call(this, game, x, y, 'gMob'); }else if(alignment === 'neutral'){ Phaser.Sprite.call(this, game, x, y, 'nMob'); }else{ Phaser.Sprite.call(this, game, x, y, 'bMob'); } }; Creature.prototype = Object.create(Phaser.Sprite.prototype); Creature.prototype.constructor = Creature; Creature.prototype.create = function = { game.add.existing(this); game.physics.p2.enable(this); this.enableBody = true; his.body.setRectangle(20, 30); this.body.fixedRotation = true; }; instead of // Creature constructor Creature = function(game, x, y, alignment){ if(alignment === 'good'){ Phaser.Sprite.call(this, game, x, y, 'gMob'); game.add.existing(this); game.physics.p2.enable(this); this.enableBody = true; this.body.setRectangle(20, 30); this.body.fixedRotation = true; }else if(alignment === 'neutral'){ Phaser.Sprite.call(this, game, x, y, 'nMob'); game.add.existing(this); game.physics.p2.enable(this); this.enableBody = true; this.body.setRectangle(20, 30); this.body.fixedRotation = true; }else{ Phaser.Sprite.call(this, game, x, y, 'bMob'); game.add.existing(this); game.physics.p2.enable(this); this.enableBody = true; this.body.setRectangle(20, 30); this.body.fixedRotation = true; } }; Creature.prototype = Object.create(Phaser.Sprite.prototype); Creature.prototype.constructor = Creature; Thanks in advance!