neonwarge04 Posted August 17, 2015 Share Posted August 17, 2015 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! Quote Link to comment Share on other sites More sharing options...
bubamara Posted August 17, 2015 Share Posted August 17, 2015 you have typo here (addChid) : this.mStage.addChid(this.mSprite); Quote Link to comment Share on other sites More sharing options...
neonwarge04 Posted August 17, 2015 Author Share Posted August 17, 2015 @bubamara Thanks a ton! I am new to JavaScript and its error reporting capability is really not helping me on the debugger. God why did JavaScript did not told me its wrong in the firstplace? Are there better debugging tools that I can simply use in the browser? Quote Link to comment Share on other sites More sharing options...
xerver Posted August 17, 2015 Share Posted August 17, 2015 Chrome dev tools are probably the best. Most tools can't tell you if a fn exists statically because it actually might at runtime, the language is too dynamic. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.