Jump to content

Extending a Sprite Class


LuckieLordie
 Share

Recommended Posts

Hi all!

 

I've been trying to recreate the Extending a Sprite example and I think I'm having trouble with where to put my source code to keep things in scope.

 

Pokeball.js

PokeBall = function (game, rotateSpeed) {    Phaser.Sprite.call(this, game, game.world.randomX, game.world.randomY, 'pokeball');    this.anchor.setTo(0.5, 0.5);    this.rotateSpeed = rotateSpeed;    var randomScale = 0.1 + Math.random();    this.scale.setTo(randomScale, randomScale)    game.add.existing(this);};PokeBall.prototype = Object.create(Phaser.Sprite.prototype);PokeBall.prototype.constructor = PokeBall;PokeBall.prototype.update = function() {    //  Automatically called by World.update    this.angle += this.rotateSpeed;};

Game.js

MissileMania.Game = function (game) {	};MissileMania.Game.prototype = {	quitButton: null,		create: function () 	{		this.quitButton = this.game.add.button(0, 0, 'button_sprite', quitOnClick, this, 0, 1, 2);			function quitOnClick()		{			this.game.state.start('MainMenu');		}		for(var i = 1; i < 20; i++)		{			new Pokeball(this.game, i);		}			},	update: function () 	{			},	shutdown: function()	{		this.quitButton.destroy();		this.quitButton = null;	}};

These two files are included in my index.html. However when my browser tried to execute line 21 of Game.js It says "Pokeball is not defined" 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...