Warning: The magic method EDD_Blocks::__wakeup() must have public visibility in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php on line 101

Warning: The magic method EDD_Blocks::__wakeup() must have public visibility in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks/edd-blocks.php on line 101

Warning: The magic method GAINWP_Manager::__wakeup() must have public visibility in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/gainwp.php on line 78

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 555

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 585

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 617

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 651

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 686

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 745

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 785

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831
{"id":2019,"date":"2017-10-03T07:37:10","date_gmt":"2017-10-03T07:37:10","guid":{"rendered":"https:\/\/phasergames.com\/?p=2019"},"modified":"2017-10-03T07:37:10","modified_gmt":"2017-10-03T07:37:10","slug":"adding-message-box-phaser-games","status":"publish","type":"post","link":"https:\/\/phasergames.com\/adding-message-box-phaser-games\/","title":{"rendered":"Adding a Message Box to your Phaser Games"},"content":{"rendered":"

How to add a\u00a0Message Box to your Phaser Game<\/h3>\n

Have you ever needed to message a player in a game? Maybe a feature isn’t available yet, or the player doesn’t have enough heath for a specific attack.\u00a0 A convenient\u00a0way is to implement a message box. Here is one method I use to do this:<\/p>\n See The Demo<\/span><\/a>\n

var StateMain = {\r\n    preload: function() {\r\n        game.load.image(\"closeButton\", \"images\/closeButton.png\");\r\n        game.load.image(\"boxBack\", \"images\/boxBack.png\");\r\n        game.load.image(\"testButton\", \"images\/testButton.png\");\r\n    },\r\n    create: function() {\r\n        \/\/create a test button to launch the message box\r\n    \tvar buttonTest=game.add.sprite(game.width\/2,game.height\/2,\"testButton\");\r\n    \tbuttonTest.anchor.set(0.5,0.5);\r\n    \tbuttonTest.inputEnabled=true;\r\n    \tbuttonTest.events.onInputDown.add(this.testMessageBox,this);\r\n    },\r\n    testMessageBox() {\r\n        \/\/call this line of code when you want to show the message box\r\n        \/\/message, width and height\r\n        this.showMessageBox(\"HELLO THERE! Put Some Text Here!\", game.width * .7, game.height * .5);\r\n    },\r\n    \/\/\r\n    \/\/w=width\r\n    \/\/h=height\r\n    \/\/\r\n    showMessageBox(text, w = 300, h = 300) {\r\n    \t\/\/just in case the message box already exists\r\n    \t\/\/destroy it\r\n        if (this.msgBox) {\r\n            this.msgBox.destroy();\r\n        }\r\n        \/\/make a group to hold all the elements\r\n        var msgBox = game.add.group();\r\n        \/\/make the back of the message box\r\n        var back = game.add.sprite(0, 0, \"boxBack\");\r\n        \/\/make the close button\r\n        var closeButton = game.add.sprite(0, 0, \"closeButton\");\r\n        \/\/make a text field\r\n        var text1 = game.add.text(0, 0, text);\r\n        \/\/set the textfeild to wrap if the text is too long\r\n        text1.wordWrap = true;\r\n        \/\/make the width of the wrap 90% of the width \r\n        \/\/of the message box\r\n        text1.wordWrapWidth = w * .9;\r\n        \/\/\r\n        \/\/\r\n        \/\/set the width and height passed\r\n        \/\/in the parameters\r\n        back.width = w;\r\n        back.height = h;\r\n        \/\/\r\n        \/\/\r\n        \/\/\r\n        \/\/add the elements to the group\r\n        msgBox.add(back);\r\n        msgBox.add(closeButton);\r\n        msgBox.add(text1);\r\n        \/\/\r\n        \/\/set the close button\r\n        \/\/in the center horizontally\r\n        \/\/and near the bottom of the box vertically\r\n        closeButton.x = back.width \/ 2 - closeButton.width \/ 2;\r\n        closeButton.y = back.height - closeButton.height;\r\n        \/\/enable the button for input\r\n        closeButton.inputEnabled = true;\r\n        \/\/add a listener to destroy the box when the button is pressed\r\n        closeButton.events.onInputDown.add(this.hideBox, this);\r\n        \/\/\r\n        \/\/\r\n        \/\/set the message box in the center of the screen\r\n        msgBox.x = game.width \/ 2 - msgBox.width \/ 2;\r\n        msgBox.y = game.height \/ 2 - msgBox.height \/ 2;\r\n        \/\/\r\n        \/\/set the text in the middle of the message box\r\n        text1.x = back.width \/ 2 - text1.width \/ 2;\r\n        text1.y = back.height \/ 2 - text1.height \/ 2;\r\n        \/\/make a state reference to the messsage box\r\n        this.msgBox = msgBox;\r\n    },\r\n    hideBox() {\r\n    \t\/\/destroy the box when the button is pressed\r\n        this.msgBox.destroy();\r\n    },\r\n    update: function() {}\r\n}<\/pre>\n\t
\n\n\t\t\n\t\t
\n\t\t\t