How do I do a 'color changer' for text?

0 favourites
  • 12 posts
From the Asset Store
Creepy Sprite Font suitable font for your Dark/Horror/Halloween games.
  • Q: What are you trying?

    A: Replicate the plugin from Minecraft servers that let you make you text go rainbow, like using this code: &u + "Text".

    Q: Then what you need?

    A: I did everything and it works almost fine, beside it consumes too much CPU because the color variable changes all the time... there is anyway to make it consumes less CPU? Another way that can I build a event?

    Tagged:

  • Bump.

  • I have no idea what you are asking about. You need to post some pictures or videos or your project file.

  • I am trying to do something like this:

    https://user-images.githubusercontent.com/45641296/149202441-8a156be2-208a-4f54-83fc-deacf8dbf731.png

    But it consumes too much CPU... why? Because I made it for example: replaces the "&2" with the correct properties that changes the color text. And it consumes about 20% to 30% of CPU and brings the FPS from 60 FPS to 40 FPS...

    Do you have any idea/solution I can do to consume less CPU?

    *Sry my bad english, I am not native.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Are you using BBcode? It should not consume much cpu. Can you post your project file?

    You can also check these examples:

    https://editor.construct.net/#open=animated-spritefont-effects
    
    https://editor.construct.net/#open=text-formatting
    
    
  • Are you running an event on the text every tick? The text object is expensive to update, so only make changes as necessary.

  • Updating a couple of texts on every tick shouldn't cause such big drop in performance.

  • Here is some screenshots... I can't upload the project because my game is 'almost' finished.

    This right here is for the 'animated color changer':

  • Ok, that explains poor performance. You are changing lots of text objects many times, and repeat this on every tick. Say, if you have 10 texts on the layout, from what I can see on the screenshot, you are making 10*11*60=6600 text updates per second, maybe more.

    An obvious fix is to not update them on every tick. Change colors in the same event where you assign texts to text objects, or in "On object created" event.

    You can also reduce the number of text updates if you replace all tags in a string variable first. For example:

    BBCodecolors On Created
     Local variable s
     Set s to BBCodecolors.text
     Set s to replace(s, "&0", "[/color][color=black]"
     Set s to replace(s, "&1", "[/color][color=darkblue]"
     ...
     BBCodecolors set text to s
    
    
  • But some texts have this 'animated' thing that can make them change colors without stop...

    There is anyway I can check if the text have changed*? (I think this might not work, but I'll try give a try...)

    *Something like the Text Box Condition "On text changed".

    Code something like:

    Check If Text Changed -> (screenshot) replace text "&2" with " ['/colour']['colour']"

  • The text doesn't change by itself, there must be some event that changes it, right? You can update colors in that event.

    Or create a function which changes text. But make sure to replace all tags in a variable first, before assigning the text to the text object.

  • Now I get it! Thank you :D

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)