Jump to content

Error while destroying Sprites from Pause menu


ashtrail
 Share

Recommended Posts

Hello,

 

I've got a strange error. I've got a quitting menu in my game which basically ask you if you want to quit or not when you click on a button (that part works fine). If ever you answer "Nope" then I will destroy without any mercy all sprites that were used to buld the quit menu (that part kinda works but wait for it...). Problem is if you can't set your mind and you click that quitting button once again, and decide to say no a second time (why would you even do that I don't know but...) and at that point no sprites are destroyed (none, not even one) but the game unpause for the rest of it and there's menu bits in the game (great T_T).

Also it throws an error at the 8th element (it doesn't destroy any of the first seven ones though) which is : "Uncaught TypeError: Cannot read property 'parentNode' of null". I've tried real hard to understand this but I don't. Why the hell does it works once and not twice?

 

Here's some code :

 

Quit Menu code :

                        quitButton = game.add.sprite(SIZE_X * 0.03, SIZE_Y * 0.03, 'quit');                        quitButton.inputEnabled = true;			quitButton.events.onInputUp.add(function ()			{				var darkScreen;				var exitButton, exitButtonText, exitButtonHitBox;				var unpauseButton, unpauseButtonText, unpauseButtonHitBox;				var showQuitMessage;				var quitTitleSprite, quitMessageSprite;								// Pause game				pauseGame(game, gameBoard);				miniature.inputEnabled = false;				quitButton.inputEnabled = false;				onMenu2 = true; // prevents the miniature and the quit button from poping on top of the darkened screen				// darken screen (black transparent sprite of the size of the screen)				darkScreen = game.add.graphics(0, 0);				darkScreen.beginFill(0x000000, 1);				darkScreen.alpha = 0.5;				darkScreen.drawRect(0, 0, SIZE_X, SIZE_Y);								// White box				showQuitMessage = game.add.graphics(0, 0);				showQuitMessage.beginFill(0xFFFFFF, 1);				showQuitMessage.drawRect(SIZE_X * 0.2, SIZE_Y * 0.15, SIZE_X * 0.6, SIZE_Y * 0.7);								// Text output				quitTitleSprite = game.add.text(SIZE_X * 0.4, SIZE_Y * 0.3, quitTitle, {font: 'bold ' + Math.floor(SIZE_Y / 15) + 'pt Arial', fill : '#000'});				quitMessageSprite = game.add.text(SIZE_X * 0.325, SIZE_Y * 0.45, quitMessage, {font: Math.floor(SIZE_Y / 30) + 'pt Arial', fill : '#000'});								// exitButton && unpauseButton graphics				exitButton = game.add.graphics(0, 0);				exitButton.beginFill(0x81DEED, 1);				exitButton.drawRect(SIZE_X * 0.35, SIZE_Y * 0.65, SIZE_X * 0.1, SIZE_Y * 0.06);				exitButtonText = game.add.text(SIZE_X * 0.38, SIZE_Y * 0.665, quitButton1Text, {font: Math.floor(SIZE_Y / 40) + 'pt Arial', fill : '#000'});								unpauseButton = game.add.graphics(0, 0);				unpauseButton.beginFill(0x81DEED, 1);				unpauseButton.drawRect(SIZE_X * 0.55, SIZE_Y * 0.65, SIZE_X * 0.1, SIZE_Y * 0.06);				unpauseButtonText = game.add.text(SIZE_X * 0.58, SIZE_Y * 0.665, quitButton2Text, {font: Math.floor(SIZE_Y / 40) + 'pt Arial', fill : '#000'});								// exitButton && unpauseButton clicking gestion				unpauseButtonHitBox = new Phaser.Rectangle(SIZE_X * 0.55, SIZE_Y * 0.65, SIZE_X * 0.1, SIZE_Y * 0.06);				exitButtonHitBox = new Phaser.Rectangle(SIZE_X * 0.35, SIZE_Y * 0.65, SIZE_X * 0.1, SIZE_Y * 0.06);								game.input.onDown.add(function(pointer)				{					if (onMenu2)					{						if (unpauseButtonHitBox.contains(pointer.x, pointer.y))							{								unpauseGame(game, gameBoard, 2, showQuitMessage, unpauseButton, exitButton, darkScreen, quitTitleSprite, quitMessageSprite, unpauseButtonText, exitButtonText);								miniature.inputEnabled = true;								quitButton.inputEnabled = true;							}						else if (exitButtonHitBox.contains(pointer.x, pointer.y))							location.reload(true);					}				});			});

Pausing function :

		function pauseGame(game, gameBoard)		{			for (var i = 0; i < NB_CELL_Y; i++)			{				for (var j = 0; j < NB_CELL_X; j++)				{					gameBoard.puzzle[i][j].sprite.inputEnabled = false;				}			}		}

Quitting the quitting menu code (or unpause function) :

                // After the menu argument, all args must be sprites and they will all be destroyed		function unpauseGame(game, gameBoard, menu)		{			var i;						if (menu == 1) // full picture Menu				onMenu = false; // useful for stopping some sprite events, and starting others			else if (menu == 2) // exit Menu				onMenu2 = false;			// Allows the sprites to be moved again			if (onMenu == false) // the game can't go back to it's normal behavior if we're still on the full picture menu			{				for (i = 0; i < NB_CELL_Y; i++)				{					for (var j = 0; j < NB_CELL_X; j++)					{						gameBoard.puzzle[i][j].sprite.inputEnabled = true;					}				}			}			// deletes the sprites that made the menu			for (i = 3; i < arguments.length; i++)			{				console.log("arg["+i+"] destroyed.");				arguments[i].destroy();							}		}

Here's the console log :

inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startpuzzle_plus.js:316 arg[3] destroyed.puzzle_plus.js:316 arg[4] destroyed.puzzle_plus.js:316 arg[5] destroyed.puzzle_plus.js:316 arg[6] destroyed.puzzle_plus.js:316 arg[7] destroyed.puzzle_plus.js:316 arg[8] destroyed.puzzle_plus.js:316 arg[9] destroyed.puzzle_plus.js:316 arg[10] destroyed.phaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled false d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: true, priorityID: 0, useHandCursor: false…}phaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}_dragPoint: d.Point_pointerData: Array[10]_tempPoint: d.PointallowHorizontalDrag: trueallowVerticalDrag: trueboundsRect: nullboundsSprite: nullbringToTop: falseconsumePointerEvent: falsedragFromCenter: falsedragOffset: d.Pointdraggable: trueenabled: truegame: d.GameisDragged: falsenext: d.InputHandlerpixelPerfect: falsepixelPerfectAlpha: 255prev: d.InputHandlerpriorityID: 0snapOffset: d.PointsnapOnDrag: falsesnapOnRelease: falsesnapX: 0snapY: 0sprite: d.SpriteuseHandCursor: false__proto__: Objectphaser.min.js:6 InputHandler startphaser.min.js:7 inputEnabled true d.InputHandler {sprite: d.Sprite, game: d.Game, enabled: false, priorityID: 0, useHandCursor: false…}phaser.min.js:6 InputHandler startpuzzle_plus.js:316 arg[3] destroyed.puzzle_plus.js:316 arg[4] destroyed.puzzle_plus.js:316 arg[5] destroyed.puzzle_plus.js:316 arg[6] destroyed.puzzle_plus.js:316 arg[7] destroyed.phaser.min.js:7 Uncaught TypeError: Cannot read property 'parentNode' of null

Actually I'm talking of sprite but there's some text and graphics too, but since it works the first time I guess ."destroy()" works on them too.

If you neef any more info I'll be glad to give it, sorry if I'm not very precise and for the high number of lines of code.

 

Thanks in advance!

 

Stupid PS : Is it me or does Syntax Highlighting in the code balise has a serious problem (or more precisly is inexistant).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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