xronn Posted October 5, 2015 Share Posted October 5, 2015 Hello, So I'm just about to add a real time chat widget to my Phaser game, but for some reason Phaser stops me from adding spaces between words in input fields and textareas. When I comment out the var game = new Phaser.game jazz it allows me to put spaces in these fields. Any ideas? Link to comment Share on other sites More sharing options...
Skeptron Posted October 5, 2015 Share Posted October 5, 2015 Did you put your Phaser code into an IIFE? http://benalman.com/news/2010/11/immediately-invoked-function-expression/ Link to comment Share on other sites More sharing options...
xronn Posted October 5, 2015 Author Share Posted October 5, 2015 This is what I have everything loads and renders fine but with the script tag at the bottom you can't have spaces in the input or textarea. <div class="container"> <div class="content"> <div id="pixelquest"> </div> <div class="chat-widget"> <div class="chat-messages"></div> <div class="input-area"> <input type="text" class="chat-name" placeholder="Your name"> <textarea class="chat-entry" placeholder="Type a message and hit enter"></textarea> </div> </div> </div> </div> <script> window.onload = function() { var game = new Phaser.Game(800, 720, Phaser.AUTO, 'pixelquest'); game.state.add('Boot', pixelquest.Boot); game.state.add('Preloader', pixelquest.Preloader); game.state.add('MainMenu', pixelquest.MainMenu); game.state.add('Game', pixelquest.Game); // Now start the Boot state. game.state.start('Boot'); }; </script> Link to comment Share on other sites More sharing options...
drhayes Posted October 5, 2015 Share Posted October 5, 2015 Does your game use the space key for anything? Phaser binds its keyboard listeners to the window. You'll have to disable Phaser's keyboard listeners while in the chat window via "game.input.keyboard.enabled = false;". Skeptron and MichaelD 2 Link to comment Share on other sites More sharing options...
xronn Posted October 6, 2015 Author Share Posted October 6, 2015 Aha, yes I'm using the space key within the game, thanks do you know how I can reference Phaser outside of the game. I would assume I could make a jQuery call with a click event, so once the user clicks a textarea I can run the snippet above? Link to comment Share on other sites More sharing options...
chg Posted October 6, 2015 Share Posted October 6, 2015 I keep seeing people asking for help and receiving a solution from others, but then marking their own comments on that assistance as the "best answer". Maybe this shouldn't bother me (ultimately it's meaningless), but it seems really rude especially when you don't even thank the people who helped you. The best answer is the person that psychically debugged your issue, not you for noticing they were right! lol Skeptron 1 Link to comment Share on other sites More sharing options...
xronn Posted October 6, 2015 Author Share Posted October 6, 2015 Thanks @chg for ranting on my thread, unfortunately at the time I was on a mobile device on a train so wasn't able to post a proper reply with an answer. However thanks for giving me at least an hour to update my thread appreciate it! Link to comment Share on other sites More sharing options...
drhayes Posted October 6, 2015 Share Posted October 6, 2015 "Reference Phaser outside of the game". I'm not sure what this means. If the library is loaded on the page you can get at it from anywhere. Do you mean your game instance? You can make it a property of window or something. Link to comment Share on other sites More sharing options...
MattMcFarland Posted October 9, 2015 Share Posted October 9, 2015 (edited) Hmm, it seems to me that you are experiencing a focus() issue. How is that chat-widget being instantiated? what js are you using to create it? Are you using any third party libs like tiny MCE?? (many of them much with the focus()) You can also try moving the chat widget inside a different DOM element, perhaps at the top, also you could try setting its z-index:9999 to see if focus is bubbling up to the canvas. You can also try setting the position of the chat widget to fixed to see what happens. I wish I could be more help, but this is what I would do in your position given the amount of knowledge of the project you have provided. I hope it does help though! EDIT: Oh I see, phaser.js binds keys to the window.. Curious as to why it would do that, I mean, shouldn't it bind only to the element it is residing in? Why does it bind to window for things? I generally try to avoid that unless absolutely necessary.. am curious as to what that would be for phaser. Edited October 9, 2015 by MattMcFarland Link to comment Share on other sites More sharing options...
Recommended Posts