Jump to content

this.mStage.addChild is not a function?


neonwarge04
 Share

Recommended Posts

This is getting frustrating by the minute. This is very trivial nothing special. Every instance of object in my game receives a Container object. But everytime adding sprite within the constructor I get this error:

this.mStage.addChild is not a function:

I need help.

 

function SpaceShip(stage){	this.mStage = stage;		this.mSprite = new PIXI.Sprite.fromFrame("spaceship.png");	this.mSprite.anchor.x = 0.5;	this.mSprite.anchor.y = 0.5;		    this.mVelocity = 5;    this.mSprite.vx = 0;    this.mSprite.vy = 0;    	this.mFireRate = 10.0;	this.mCollisionRadius = this.mSprite.width / 2.0;	this.mIsMarkedDestroyed = false;		this.mBullets = [];	this.mLastCalledTime = Date.now();	this.mElapsed = 0.0;	this.mPixelPosition = {x : 0 , y : 0};	this.mOnPixelPositionChanged = function(lastPosition , newPosition){}		this.mStage.addChid(this.mSprite);}SpaceShip.prototype.markDestroyed = function(){	this.mIsMarkedDestroyed = true;}SpaceShip.prototype.isMarkedDestroyed = function(){	return this.mIsMarkedDestroyed;}SpaceShip.prototype.setOnPositionChanged = function(callback){	this.mOnPixelPositionChanged = callback;}SpaceShip.prototype.setPixelPosition = function (position){	var previousPosition = this.mPixelPosition;		this.mPixelPosition.x = position.x;	this.mPixelPosition.y = position.y;		this.mOnPixelPositionChanged(previousPosition , this.mPixelPosition);			this.mSprite.position.x = this.mPixelPosition.x;	this.mSprite.position.y = this.mPixelPosition.y;}SpaceShip.prototype.getSprite = function(){	return this.mSprite;}SpaceShip.prototype.getVelocity = function(){    return this.mVelocity;}SpaceShip.prototype.update = function(){	var delta = (new Date().getTime() - this.mLastCalledTime);	this.mLastCalledTime = new Date();	this.mElapsed += (delta / 1000.0);		if(this.mElapsed >= this.mFireRate)	{		this.fireBullet();		this.mElapsed = 0.0;	}		for(var bullets in this.mBullets)		bullets.update();}SpaceShip.prototype.fireBullet = function(){	this.mBullets.push(new Bullet(this , this.mStage))}function Bullet(spaceship , stage){	this.mSprite = new PIXI.Sprite.fromFrame("bullet.png");	this.mSprite.anchor.x = 0.5;	this.mSprite.anchor.y = 0.5;			this.mSprite.vx = 30;			this.mSprite.x = spaceship.getSprite().x;	this.mSprite.y = spaceship.getSprite().y;		stage.addChild(mSprite);}Bullet.prototype.update = function(){	this.mSprite.y += this.mSprite.vx;}

The error occurs initially at end before the '}' of SpaceShip(stage).

 

Thanks!
 

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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