noxoc Posted February 15, 2014 Share Posted February 15, 2014 I'm trying to create a Player-Prototype by extending the Sprite-Prototype – as shown in the examples. It 'seems' to work, all the data is in Place – but it's not rendering the sprite. Why? :/(function (Phaser) { var game = new Phaser.Game(800, 600, '', Phaser.AUTO); var game_state = {}; var player; function Player(game, x, y) { Phaser.Sprite.call(this, game, x, y, 'chick') console.log(this); } Player.prototype = Object.create(Phaser.Sprite.prototype); Player.prototype.constructor = Player; Player.preload = function (game) { game.load.image('chick', '/assets/chick.png'); }; game_state.main = function () {}; game_state.main.prototype = { preload: function () { Player.preload(game); }, create: function () { player = new Player(game, game.world.randomX, game.world.randomY); }, update: function () { } }; game.state.add('main', game_state.main); game.state.start('main');})(window.Phaser) Link to comment Share on other sites More sharing options...
hpcodecraft Posted February 15, 2014 Share Posted February 15, 2014 I think you did not add the sprite to the game - try insertinggame.add.existing(this);after your Phaser.Sprite.call in the create function anthkris 1 Link to comment Share on other sites More sharing options...
noxoc Posted February 15, 2014 Author Share Posted February 15, 2014 Awesome! That works. I'll open a ticket that this line gets added to the example. Link to comment Share on other sites More sharing options...
rich Posted February 28, 2014 Share Posted February 28, 2014 Awesome! That works. I'll open a ticket that this line gets added to the example. But that line IS in the example // Here is a custom game objectMonsterBunny = function (game, x, y, rotateSpeed) { Phaser.Sprite.call(this, game, x, y, 'bunny'); this.rotateSpeed = rotateSpeed;};MonsterBunny.prototype = Object.create(Phaser.Sprite.prototype);MonsterBunny.prototype.constructor = MonsterBunny;/** * Automatically called by World.update */MonsterBunny.prototype.update = function() { this.angle += this.rotateSpeed;};var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });function preload() { game.load.image('bunny', 'assets/sprites/bunny.png');}function create() { var wabbit = new MonsterBunny(game, 200, 300, 1); wabbit.anchor.setTo(0.5, 0.5); var wabbit2 = new MonsterBunny(game, 600, 300, 0.5); wabbit2.anchor.setTo(0.5, 0.5); game.add.existing(wabbit); game.add.existing(wabbit2);} Link to comment Share on other sites More sharing options...
Recommended Posts