Jump to content

Extending a Sprite Class


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


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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