azdev Posted March 19, 2015 Share Posted March 19, 2015 How can I show & hide texts, sprites and images? Link to comment Share on other sites More sharing options...
darkraziel Posted March 19, 2015 Share Posted March 19, 2015 You can use game.add() to create new objects like:game.add.sprite(0,0,'mySprite');More info here:http://docs.phaser.io/Phaser.GameObjectFactory.html If you just want to make an object invisible you can change it's alpha property like this:mySprite.alpha = 0;or you can change it's visible property to false like this:mySprite.visible = false;You can find more info on sprites on the same page that I linked before. Good Luck! tntlad09 and FinalFantasyVII 2 Link to comment Share on other sites More sharing options...
sbonavida Posted October 26, 2016 Share Posted October 26, 2016 Hello, and text? Alpha or visible properties are not working for me with text. Create method: this.text = this.game.add.bitmapText(540, 60, 'gosmick','Hello Word', 112); //It's fine. Text shows. ../.. Update method: this.text.alpha = 0; //It's not working this.text.visible = false; //It's not working And the text still shows in screen. ¿? ¿? ¿? Thanks for your help. Link to comment Share on other sites More sharing options...
s4m_ur4i Posted October 27, 2016 Share Posted October 27, 2016 Without knowing better, I would just set the text Y or X coordinate out of screen - Link to comment Share on other sites More sharing options...
sbonavida Posted October 27, 2016 Share Posted October 27, 2016 Thank you SamTheMighty. I tested your propossal, but It's not working, Text is pemanently in the same position. I don't understand it. Sprites are working very well for me, they show or not when I write it, but text.. :-< Thanks. Link to comment Share on other sites More sharing options...
sbonavida Posted October 27, 2016 Share Posted October 27, 2016 I try too... this.game.world.remove(this.text); It doesn't work. ;-< Link to comment Share on other sites More sharing options...
sbonavida Posted October 27, 2016 Share Posted October 27, 2016 Neither... this.text.destroy(); It's the mistery of Bitmaptext. Are they impossible to hide? Maybe, someone will illuminate our dark path. ^^ Link to comment Share on other sites More sharing options...
sbonavida Posted October 28, 2016 Share Posted October 28, 2016 OMG. The mistery has a solution. ¡It was my fault! The scope of variables were in bad place. :-< Anyway, the behavior is strange because the "sprite variable" was in the same place "text variable", and sprite was working and text not.https://phaser.io/examples/v2/text/remove-text Sorry, I'm newbie. I love this framework. It's absolutely great!! Thanks you. Link to comment Share on other sites More sharing options...
charlieRobinson Posted November 2, 2016 Share Posted November 2, 2016 Hi, guys. another newbie here. I have a key listener in my update loop that listens for key to show and hide a menu. Problem is, the toggle isnt a hard toggle but a fully automatic toggle. The menu flashes if you hold the bound key down. How can I keep the listener in the update loop but make it a hard toggle without the full auto flash effect? Thank you! Link to comment Share on other sites More sharing options...
ForgeableSum Posted November 4, 2016 Share Posted November 4, 2016 On 11/2/2016 at 4:08 PM, charlieRobinson said: Hi, guys. another newbie here. I have a key listener in my update loop that listens for key to show and hide a menu. Problem is, the toggle isnt a hard toggle but a fully automatic toggle. The menu flashes if you hold the bound key down. How can I keep the listener in the update loop but make it a hard toggle without the full auto flash effect? Thank you! Don't put the listener in the update loop. That's just not how to do it. Simply enable input on the sprite (with sprite.inputEnabled = true) and add an event listener on the sprite with: sprite.events.onInputDown.add(function() { if (menuSprite.visible) { menuSprite.visible = false; } else { menuSprite.visible; } }); It doesn't have to be more complicated than that :). Link to comment Share on other sites More sharing options...
charlieRobinson Posted November 8, 2016 Share Posted November 8, 2016 Thank you. If I wanted to bind the 'E' key to that sprite listener, how we do I do that? I am currently using: E = this.game.input.keyboard.isDown(Phaser.Keyboard.E); But I am not sure if that code will work with your example? Thank you! Also, the tutorials I am finding show binding the key to the variable and then detecting it in the update loop. I am not sure how to create a listener for a key that is outside the update loop. Thank you! http://phaser.io/examples/v2/input/key EDIT:::: I think I am on to something with the example code below key1 = game.input.keyboard.addKey(Phaser.Keyboard.ONE); key1.onDown.add(addPhaserDude, this); function addPhaserDude () { game.add.sprite(game.world.randomX, game.world.randomY, 'phaser'); } Link to comment Share on other sites More sharing options...
charlieRobinson Posted November 8, 2016 Share Posted November 8, 2016 ok... new problem... so I have the function bound key press working. Thank you! Problem now is that I can no longer use the 'E' key while chatting. the menu toggle is contingent on if (!isChatting) so if player is not chatting they cant toggle the menu so as to not interfere with using the 'E' key while chatting. But now the 'E' key seems bound only to the menu toggle and wont appear in the text field to chat. Do I need to toggle the key listener off and on when the player (isChatting) boolean is true? All of the other keys being detected in the update loop are working fine in chat, BTW. Thank you! EDIT::::: Looks like this is the code I am looking for: game.input.keyboard.removeKey(Phaser.Keyboard.E); The idea now is to add and remove 'E' key when player is filling out text boxes. Any better way to do this? Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts