klg

Invalidate stage to force redraw

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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";

Share this post


Link to post
Share on other sites

Hi Michael,

 

Thanks for the reply. I use

sprite.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 like

config.colors.primaryColor = newColorValue;

does not work. 

 

Is there any way to force stage to redraw all elements?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.