Change text color using Javascript

0 favourites
  • 3 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hello everyone,

    I have a text object name "A" and I want to change color of it using Javascript (instead of action). I tried to code like this but it's not works. I don't know that I made something wrong or not or maybe Construct hasn't support this feature yet.

    let textA = null;
    
    runOnStartup(async runtime =>
    {
    	// Code to run on the loading screen.
    	// Note layouts, objects etc. are not yet available.	
    	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
    });
    
    async function OnBeforeProjectStart(runtime)
    {						 
    	// Code to run just before 'On start of layout' on
    	// the first layout. Loading has finished and initial
    	// instances are created and available to use here.
    	textA = runtime.objects.A.getFirstInstance();
    	
    	runtime.addEventListener("tick", () => Tick(runtime));
    
    }
    
    function Tick(runtime)
    {		
    	// Code to run every tick
    	textA.colorRgb = (255, 0, 0);
    }
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • A few things:

    1. First, the text object must be white for this to work.
    2. Second, the colorRgb value assignment must use proper array syntax, brackets instead of parentheses.
    3. Finally, you should use values between 0 and 1 in your array, so red is [1,0,0].
  • Thank so much Magistross . I did it!

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