Nikow Posted May 29, 2015 Share Posted May 29, 2015 Hi ! I'm creating a spaceshooter game, and randomly i have this error message :>Uncaught TypeError: Cannot read property 'right' of nullI really don't understand this error wich is pointed at phaser.js:61080 ?? Please help... Thanks Link to comment Share on other sites More sharing options...
Lomaz Posted May 29, 2015 Share Posted May 29, 2015 Looks like you're putting a null into a phaser function, causing the actual script to crap out on you, can you post your JS so we can hunt down the issue? Link to comment Share on other sites More sharing options...
Nikow Posted June 1, 2015 Author Share Posted June 1, 2015 Thank you, yes, my js :/** * Le Framework de jeux JavaScript Phaser *Phaser v2.0.5 - http://phaser.io - @photonstorm - (c) 2014 Photon Storm Ltd. https://github.com/photonstorm/phaserhttp://examples.phaser.io/ *//** * Classe de gestion du jeu * Le moteur... * * @param {[type]} game [description] * @return {[type]} [description] */var theGame = function(game){ // déclaration des variables elapsedTime = 0, gyroMove=0, background=null,player=null,b1=null,b2=null,b3=null,b4=null,batGenerator=null,shoots=null,shootGenerator=null; parallaxe = null, ginterface=null, life=3,weaponType=1,ufoLife1=null,ufoLife2=null,ufoLife3=null,planetes=null,planeteGenerator=null,asteroides=null,asteroidesGenerator=null; aldo=null,score=0,ratioDefil=1,shipTrail=null,getLifes=null,getLife=null;}/** * Les méthodes * * @type {Object} */theGame.prototype ={ /** * Création de la scène du jeu, * mise en place des graphismes... * * @return {[type]} [description] */ create : function() { game.physics.startSystem(Phaser.Physics.ARCADE); // Background game.stage.backgroundColor = '#000000';// la couleur de fond du jeu background = game.add.tileSprite(game.width/2,0,640,4417,"background"); background.anchor.setTo(0.5,0); planetes = game.add.group(); planetes.enableBody = true; planetes.physicsBodyType = Phaser.Physics.ARCADE; planetes.setAll('checkWorldBounds', true); planetes.setAll('outOfBoundsKill', true); planeteGenerator = this.game.time.events.loop(Phaser.Timer.SECOND * game.rnd.integerInRange(3, 7), this.createPlanete, this); planeteGenerator.timer.start(); parallaxe = game.add.tileSprite(game.width/2,0,640,961,"parallaxe"); parallaxe.anchor.setTo(0.5,0); shoots = game.add.group(); shoots.enableBody = true; shoots.physicsBodyType = Phaser.Physics.ARCADE; shoots.setAll('checkWorldBounds', true); shoots.setAll('outOfBoundsKill', true); asteroides = game.add.group(); asteroides.physicsBodyType = Phaser.Physics.ARCADE; asteroides.enableBody = true; asteroides.setAll('checkWorldBounds', true); asteroides.setAll('outOfBoundsKill', true); asteroidesGenerator = this.game.time.events.loop(Phaser.Timer.SECOND * game.rnd.integerInRange(1, 3), this.createAsteroide, this); asteroidesGenerator.timer.start(); getLifes = game.add.group(); getLifes.physicsBodyType = Phaser.Physics.ARCADE; getLifes.enableBody = true; getLifes.setAll('checkWorldBounds', true); getLifes.setAll('outOfBoundsKill', true); getLifeGenerator = this.game.time.events.loop(Phaser.Timer.SECOND * game.rnd.integerInRange(3, 15), this.createGetLife, this); getLifeGenerator.timer.start(); // player player = game.add.sprite(this.game.width/2,game.height-150,'spaceShip'); player.anchor.setTo(0.5,0.5); game.physics.arcade.enable(player); player.body.collideWorldBounds=true; shootGenerator = this.game.time.events.loop(Phaser.Timer.SECOND/2 , this.createShoot, this); shootGenerator.timer.start(); ginterface = game.add.sprite(game.width/2,0,"gui"); ginterface.anchor.setTo(0.5,0); this.game.time.events.loop(Phaser.Timer.SECOND*2, this.loopSec, this); var currentTime = game.time.time; this.updateLife(); aldo = game.add.bitmapText(560, 14, 'aldo',score+' pts', 40); aldo.anchor.x = 1; gyro.frequency = 50; gyro.startTracking(function(o) { // updating player velocity gyroMove = o.gamma; }); this.game.world.bringToTop(ginterface); this.game.world.bringToTop(ufoLife1); this.game.world.bringToTop(ufoLife2); this.game.world.bringToTop(ufoLife3); this.game.world.bringToTop(aldo); }, update : function(){ background.tilePosition.y += 6 * ratioDefil; parallaxe.tilePosition.y += 7 * ratioDefil; player.body.velocity.setTo(0, 0); if(life==3) { player.frame = 1; } else if(life == 2) { player.frame = 4; } else if(life == 1) { player.frame = 7; } //shipTrail.x = player.x; //game.physics.arcade.collide(shoots, planetes, this.shootPlanete(this.shoot, this.planete),null,this); game.physics.arcade.overlap(shoots, asteroides, this.shootPlanete,null,this); game.physics.arcade.overlap(player, asteroides, this.shootPlayer,null,this); game.physics.arcade.overlap(player, getLifes, this.addLifePlayer,null,this); if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT) || gyroMove < -20) { player.body.velocity.x = -450; if(life==3) { player.frame = 0; } else if(life == 2) { player.frame = 3; } else if(life == 1) { player.frame = 6; } } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT) || gyroMove > 20) { player.body.velocity.x = 450; if(life==3) { player.frame = 2; } else if(life == 2) { player.frame = 5; } else if(life == 1) { player.frame = 8; } } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { ratioDefil = 0.5; player.frame = 1; } else if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { ratioDefil = 1; player.frame = 1; } else if (game.input.activePointer.isDown) { if(game.input.x < this.game.width/2) { player.body.velocity.x = -300; player.frame = 0; } else if (game.input.x >= this.game.width/2) { player.body.velocity.x = 300; player.frame = 2; } } }, shootPlanete : function(shoot,asteroid) { asteroid.life -= shoot.damage; if(asteroid.life <= 0) { shoot.kill(); asteroid.kill(); var boom = game.add.sprite(asteroid.x,asteroid.y,'bigExplode'); game.physics.arcade.enable(boom); boom.anchor.setTo(0.5,1); boom.scale.setTo(asteroid.scale.x,asteroid.scale.y); boom.animations.add('kaboom',[0,1,2,3,4,5,6,7]); boom.animations.play('kaboom',15,false,true); boom.body.velocity.y = asteroid.body.velocity.y-50; score +=100*asteroid.scale.x; shoot.destroy(); asteroid.destroy(); } shoot.kill(); shoot.destroy(); score +=10*asteroid.scale.x; aldo.setText(score+' pts'); if(score >= 300 && score <= 600) { weaponType = 2; } else if(score >= 600 && score <= 999) { weaponType = 3; } else if(score >= 1000 && score <= 1500) { weaponType = 4; } else if(score >= 1500) { weaponType = 5; } }, shootPlayer : function(player,asteroid) { asteroid.destroy(); life --; this.updateLife(); }, createPlanete : function() { var choosePlanete = game.rnd.integerInRange(1, 2); console.log(choosePlanete); if(choosePlanete == 1) { var b1 = planetes.create(game.rnd.integerInRange(0, 640),-200, 'p1'); b1.body.velocity.y = 240 * ratioDefil; } else if(choosePlanete == 2) { var b2 = planetes.create(game.rnd.integerInRange(0, 640),-200, 'p2'); b2.body.velocity.y = 240 * ratioDefil; } console.log('Planete crée'); }, createAsteroide : function() { asteroides.add(new Asteroides(game, game.rnd.integerInRange(0, 640-117),0)); console.log('Asteroide crée'); }, createGetLife : function() { getLife = getLifes.create(game.rnd.integerInRange(0, 640),-200, 'getLife'); getLife.body.velocity.y = 240 * ratioDefil; console.log('Life crée'); }, addLifePlayer : function() { if (life < 3) { life ++; this.updateLife(); } getLife.kill(); getLife.destroy(); }, updateLife : function() { if(life == 3) { ufoLife3 = game.add.sprite(71,12,"ufoVie"); ufoLife2 = game.add.sprite(150,12,"ufoVie"); ufoLife1 = game.add.sprite(230,12,"ufoVie"); } else if(life == 2) { ufoLife1.kill(); } else if(life == 1) { ufoLife1.kill(); ufoLife2.kill(); } else { ufoLife1.kill(); ufoLife2.kill(); ufoLife3.kill(); console.log('YOU DIE!') player.kill(); shootGenerator.timer.stop(); var boomUfo = game.add.sprite(player.x,player.y-40,'exlodeUfo'); boomUfo.anchor.setTo(0.5,0.5); boomUfo.animations.add('kaboom',[0,1,2,3,4,5,6]); boomUfo.animations.play('kaboom',12,false,true); } }, createShoot : function() { if(weaponType == 1) { shoots.add(new shootWeapon(game, player.x, player.y-50, 'blast1',-400,0,5)); } else if(weaponType == 2) { shoots.add(new shootWeapon(game, player.x, player.y-50, 'blast1',-400,-10,5)); shoots.add(new shootWeapon(game, player.x, player.y-50, 'blast1',-400,10,5)); } else if(weaponType == 3) { shoots.add(new shootWeapon(game, player.x, player.y-50, 'blast2',-600,0,10)); } else if(weaponType == 4) { shoots.add(new shootWeapon(game, player.x, player.y-50, 'blast2',-600,8,10)); shoots.add(new shootWeapon(game, player.x, player.y-50, 'blast2',-600,-8,10)); } else if(weaponType == 5) { shoots.add(new shootWeapon(game, player.x, player.y-50, 'blast1',-400,0,5)); shoots.add(new shootWeapon(game, player.x, player.y-50, 'blast2',-600,8,10)); shoots.add(new shootWeapon(game, player.x, player.y-50, 'blast2',-600,-8,10)); } }, loopSec : function(){ elapsedTime += game.time.elapsed; console.log('Loop Count: '+ elapsedTime, 32, 64); }} Link to comment Share on other sites More sharing options...
Nikow Posted June 2, 2015 Author Share Posted June 2, 2015 up ...? Link to comment Share on other sites More sharing options...
Nikow Posted June 4, 2015 Author Share Posted June 4, 2015 Need help... Please :/ Link to comment Share on other sites More sharing options...
Nikow Posted June 8, 2015 Author Share Posted June 8, 2015 If you need more informations, ask me, i really don't understand what the prob is... It's could be working during one hour, but sometimes it's stoping about 30 seconds.... Link to comment Share on other sites More sharing options...
1ipt0n Posted June 8, 2015 Share Posted June 8, 2015 probably you destroy sprite and than phaser is trying to check collisions with it. You can try to destroy it in next update. for example like that. //instead of somesprite.destroy();somesprite.destroy_in_next_tick= true; and in the very begining of update: for(var x=0; x<game.world.children.length; x++) if(game.world.children[x].destroy_in_next_tick) game.world.children[x].destroy(true); Cyclone112 1 Link to comment Share on other sites More sharing options...
Nikow Posted June 8, 2015 Author Share Posted June 8, 2015 How is it possible ? I have to do that for every sprite wich could be destroyed ??? Link to comment Share on other sites More sharing options...
1ipt0n Posted June 8, 2015 Share Posted June 8, 2015 just try to replace it and You will see is this is the reason You are getting this error.But for what I see there it's a phaser function that check collisions. all you have to do it's to replace destroy() line. for loop will do the rest for all of your sprites. Link to comment Share on other sites More sharing options...
1ipt0n Posted June 8, 2015 Share Posted June 8, 2015 and it's possible becouse first you destroy asteroid in this line: game.physics.arcade.overlap(shoots, asteroides, this.shootPlanete,null,this); and than You check collision with asteroids :game.physics.arcade.overlap(player, asteroides, this.shootPlayer,null,this); but for some reason phaser is looking for bodies that are no longer there. Link to comment Share on other sites More sharing options...
Nikow Posted June 8, 2015 Author Share Posted June 8, 2015 and it's possible becouse first you destroy asteroid in this line: game.physics.arcade.overlap(shoots, asteroides, this.shootPlanete,null,this); and than You check collision with asteroids :game.physics.arcade.overlap(player, asteroides, this.shootPlayer,null,this); but for some reason phaser is looking for bodies that are no longer there. Ow ! It's beacause i have many test on asteroids ?...So if i destroy asteroids on next tick it could be resolve the prob ! I will try it Thanks Link to comment Share on other sites More sharing options...
Nikow Posted June 10, 2015 Author Share Posted June 10, 2015 Hi , your solution resolve the prob on pc ! But not on mobile devices.... Do you know why ? Link to comment Share on other sites More sharing options...
Nikow Posted June 11, 2015 Author Share Posted June 11, 2015 Edit : Problem not solved... On any devices... Really need your help, js console give me this line of my code :game.physics.arcade.overlap(shoots, asteroides, this.shootPlanete,null,this); Link to comment Share on other sites More sharing options...
ZoomBox Posted June 11, 2015 Share Posted June 11, 2015 I think your problem comes from the multiple .destroy() functions.You should be able to use .kill() only, even if your game doesn't works as good as previously, see if it still crashes.If it doesn't crash anymore, you know where the problem is... Nikow 1 Link to comment Share on other sites More sharing options...
Nikow Posted June 11, 2015 Author Share Posted June 11, 2015 okay.. i will try this, but if i doesn't use destroy anymore, how can i delete sprites from memory? Link to comment Share on other sites More sharing options...
ZoomBox Posted June 11, 2015 Share Posted June 11, 2015 Let's first try to know where is the problem and then we will see ! Link to comment Share on other sites More sharing options...
Nikow Posted June 11, 2015 Author Share Posted June 11, 2015 Destroy() seems to be the prob... So, how can i replace this function ? Thank you ZoomBox EDIT : I think i need to reset my extendedSprites ??? How can i do that ? Link to comment Share on other sites More sharing options...
ZoomBox Posted June 11, 2015 Share Posted June 11, 2015 Now do a null test before this line:game.physics.arcade.overlap(shoots, asteroides, this.shootPlanete,null,this);for each objects (if shoots == null or asteroides == null)And put a breakpoint inside to see if it ever falls in this condition.You should also do the test for each shoot in shoots and each asteroide in asteroides. Edit: You'll, for sure, fall in one of those cases. So just manage to know why the null object is null and you'll solve the problem. Link to comment Share on other sites More sharing options...
Nikow Posted June 11, 2015 Author Share Posted June 11, 2015 For everybody : destroy() are the probs, i replace all of them by remove() and it's works perfectly now Thanks all Link to comment Share on other sites More sharing options...
MichaelD Posted June 12, 2015 Share Posted June 12, 2015 What does .remove() do? Is it in the docs? Link to comment Share on other sites More sharing options...
Recommended Posts