klg Posted May 1, 2015 Share Posted May 1, 2015 Hi All, Is there a way to invalidate stage and force phaser to redraw all elements on it? Basically my game is supposed to have multiple themes and user can change themes after the game is loaded.Currently I have a javascript object with all the theme colors but it seems like just changing the primary color value in the object does not update elements/buttons using it. Is there a way to achieve this? Thank You so much in advance. Link to comment Share on other sites More sharing options...
MichaelD Posted May 1, 2015 Share Posted May 1, 2015 The game updates usually with 60 frames per second, if the change is applied correctly it will be displayed. Is the color value specifically set upon each element? Meaning, If you have a variable with the color and you set the color of the elements based on that variable and then change the variable the elements do not inherit the change. Like: sprite.tint = "#ff0000"; klg 1 Link to comment Share on other sites More sharing options...
klg Posted May 1, 2015 Author Share Posted May 1, 2015 Hi Michael, Thanks for the reply. I usesprite.tint = config.colors.primaryColor;to set the colors when these sprites are created. This is done for multiple sprites and some sprites have different colors. To change the color again with sprite.tint, I will need to keep a track of all these sprites globally since they are present in different functions. Also, as you said in your reply, just updating the color likeconfig.colors.primaryColor = newColorValue;does not work. Is there any way to force stage to redraw all elements? Link to comment Share on other sites More sharing options...
drhayes Posted May 1, 2015 Share Posted May 1, 2015 The stage redraws every frame. I think you mean "is there a way to get every child in the stage to refresh its texture", if that helps with your Googling. I don't think there's a way to automatically do that. When the user changes the theme you're probably either going to have to re-instantiate every affected Sprite or Image, or iterate through all of your groups calling setProperty with the new tint value (or whatever). The reason this doesn't work is the color values are value types, not reference types. Changing the value in one object won't change the value in another object. If you built these textures using BitmapData you can set its "dirty" property to true to re-render it as well. EDIT: Whoops, I meant setAllChildren not setProperty. MichaelD and klg 2 Link to comment Share on other sites More sharing options...
MichaelD Posted May 1, 2015 Share Posted May 1, 2015 Basically its what drhayes said, however you could extend all the objects of the theme and add a check inside their update function, although I suspect this is the worst solution performance wise. klg 1 Link to comment Share on other sites More sharing options...
klg Posted May 2, 2015 Author Share Posted May 2, 2015 Thanks for the help. I'll do as dryahes said. Link to comment Share on other sites More sharing options...
Recommended Posts