noxoc

Extended Sprite is not rendering

Recommended Posts

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)

Share this post


Link to post
Share on other sites

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);}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.