mandarin Posted January 6, 2014 Share Posted January 6, 2014 Hi. I use Phaser 1.1.3, and this code gives me this error:Uncaught TypeError: Object TurnGroup has no method 'addChild' at line 10897 Here's the code:<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <script src="js/phaser.min.js"></script></head><body><div id="gameContainer"></div><script type="text/javascript">SQ = {};SQ.Game = function(game) { this.game = game;};SQ.Game.prototype = { create: function() { this.turn = new SQ.Turn(this); }};SQ.Turn = function(sq_game) { Phaser.Group.call(this, sq_game.game, 'TurnGroup', true);};SQ.Turn.prototype = Object.create(Phaser.Group.prototype);SQ.Turn.prototype.constructor = SQ.Turn;window.onload = function() { var game = new Phaser.Game(288, 512, Phaser.CANVAS, 'gameContainer'); game.state.add('Game', SQ.Game); game.state.start('Game');};</script></body></html> Link to comment Share on other sites More sharing options...
rich Posted January 6, 2014 Share Posted January 6, 2014 The parameters in your SQ.Turn don't appear to match what Group is expecting: http://phaser.io/docs/Phaser.Group.html Try this:SQ.Turn = function(sq_game) { Phaser.Group.call(this, sq_game.game, null, 'TurnGroup', true);};As I don't believe you've got a parent object anywhere. Link to comment Share on other sites More sharing options...
mandarin Posted January 6, 2014 Author Share Posted January 6, 2014 Ok, that works. According to the documentation Phaser.Group accepts only 4 parameters. Is the 5th documented? Link to comment Share on other sites More sharing options...
rich Posted January 6, 2014 Share Posted January 6, 2014 No, there are only 4 parameters. Link to comment Share on other sites More sharing options...
RickB Posted January 6, 2014 Share Posted January 6, 2014 Ok, that works. According to the documentation Phaser.Group accepts only 4 parameters. Is the 5th documented? This one used to confuse me too, and I don't know the official reason why, but the 'this' parameter in the function param list below is part of what is required when calling the generic implementation. It never makes it to Phaser.Group constructor.Phaser.Group.call(this, sq_game.game, null, 'TurnGroup', true);See the answer here for a little more detail http://stackoverflow.com/questions/560829/calling-base-method-using-javascript-prototype Link to comment Share on other sites More sharing options...
rich Posted January 6, 2014 Share Posted January 6, 2014 Right, that's just standard JavaScript: http://dochub.io/#javascript/function.call Link to comment Share on other sites More sharing options...
Recommended Posts