Jump to content

Tween Background Color


markware
 Share

Recommended Posts

I believe that because backgroundColor is stored as a string, you can not tween the value.  

 

You could create a number variable to store the background color, tween that variable, and then convert that value to a string and set the background color every frame in the update loop.  

 

Because backgroundColor is a property, setting the value every frame might be expensive computationally.  

Link to comment
Share on other sites

solution

 

function blendColors(c0, c1, p) {
    var f=parseInt(c0.slice(1),16),t=parseInt(c1.slice(1),16),R1=f>>16,G1=f>>8&0x00FF,B1=f&0x0000FF,R2=t>>16,G2=t>>8&0x00FF,B2=t&0x0000FF;
    return "#"+(0x1000000+(Math.round((R2-R1)*p)+R1)*0x10000+(Math.round((G2-G1)*p)+G1)*0x100+(Math.round((B2-B1)*p)+B1)).toString(16).slice(1);
}
function makecolor(colore){
game.stage.backgroundColor=colore;
}
function coloru(colorpanel){
var i=1;
colorpanel.forEach(function(entry) {
    i=i+50;
    setTimeout(function(){makecolor(entry)}, 100+i);
});
    
    return false;
    }

function weather(colour,colourto){
colorpanel=[];
for(i=0;i<=10;i++){
    var color=blendColors(colour,colourto,i/10);
    colorpanel.push(color);

    }
    
    coloru(colorpanel)


 

}

 

 

its bad and nasty but i post it for discussion

Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...