Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Background Colour

VP
Guest
Quote
2022-01-08 12:55:59

I'm trying to run this special command "Before First Draw" to change the background colour to light-blue as the scene starts.....

var root = ccbGetRootSceneNode();
ccbSetSceneNodeProperty(root, "BackgroundColor", 128,255,255);

There are no reported errors but nothing happens, the background colour stays Dark-Red from the scene before and isn;t changed to light-blue.

Any ideas why it doesn't work?

Thanks.


just_in_case
Moderator
Quote
2022-01-08 14:12:51

Are you sure, it is not working for you? there might be something else in your project that might be conflicting with the above code, I just checked the exact code on my side, and it was working absolutely fine, light blue is showing up as background color when the scene starts.

try cross-checking if you are having another code in your project that deals with background color, or some code that is preventing the above code from execution.

Also if you are having difficulty with setting correct colors, then you can check out my color conversion function to get the correct color values. here is the link to the code snippets on the Neophyte website.

https://neophyte.cf/CS_color_con...


VP
Guest
Quote
2022-01-08 21:05:44

Thanks just_in_case. Good to know it's working properly. Still doesn't work for me this time unfortunately.

No, there's no other code in the game which I can imagine would cause such a conflict - this is the only code I've tried in this game (other than hide mouse pointer). The only reason I tried it was because Scene1 had a red background and scene2 had a blue background but the background wasn't changing colour when I switched scenes (scene 2 was using the same red from scene1) - so that's why I tried using the code (to force a colour change) but still the background colour still didn't change to blue when switching scenes (however, it was blue if I ran the scene manually from the Coppercube Editor - but not when using the "switch scene" command).

It seems that coppercube may still have some complex little problems with the "Before First Draw" (I also sometimes still have issues with "IF" variable statements when I call them with "Before First Draw" behaviour).

I can fix the colour change by changing the colour after the scene has loaded - but then player can notice the colour-change from red to blue as the scene starts.

As a workaround, I fixed it by removing the "Background Color" code and just used a billboard instead (and applied a blue coloured texture to it) which I stretched out to fill the entire screen.

I can now change the colour by switching textures of the billboard instead of trying to Dynamically change the RGB values of the Background.

I also managed to fix the "IF" variable problem, by adding a folder node with "Every Few Seconds...IF...." instead of using the "Before First Draw" behaviour - probably not the best way to fix it but everything now works as expected.

Thanks for posting the colour converter too, I'll take a look at it!


DouweDabbe
Guest
Quote
2022-01-09 03:11:58

I also have weird problems with code that disappear once I reinstall the app.
But watch out with your unique extensions in the documents folder as this will be overwritten - do not loose your work !!!


csp-games
Guest
Quote
2022-01-09 12:32:52

It works here. With a new level, empty but a cube and a hidden skybox. Tested for EXE and WebGL.


VP
Guest
Quote
2022-01-09 18:11:34

Thanks both!

Yeah, I could be making a mistake somewhere.

Here's a quick ccb file with the same issue (rather than the entire game file).

It's 2 scenes (both with the change background colour script in the "before first draw (and also on reload)).

I set keys "1" & "2" to switch between the scenes but for me colour doesn't appear to change properly (it stays the same colour for both scenes (although l noticed that I get different results depending which scene I is selected in the coppercube editor when I run the program - this implies that the script is running at least once at game start, but not every time the scene starts) ....

Scene 1 should be 128,255,255
Scene 2 should be 58,25,85

https://drive.google.com/file/d/...

Would anyone mind checking it for me to see if you can find any conflicts or mistakes please? As I say, I managed a workaround by using a billboard for background colour but I'd like to start to learn the basics of how to code properly.

Thanks!


csp-games
Guest
Quote
2022-01-10 01:57:39

Sorry I still got 6.4 installed, and may update only after reading the dev logs. It cannot load your file. btw.
However may I suggest to use some alternative? Like fading in and out a screensize texture, or just fade to black ,or white.

Or try to change the color somewhere else, not in the on Before thing. You could also fade the bg color to the next one before switching to the next scene.

Seems like many things are done in parallel threads, this probably too.

Maybe try something like:


ccbRegisterOnFrameEvent( nuBGcolor );
function nuBGcolor()
{
var r=Math.random()*255;
var g=50;
var b=Math.random()*255;;

var root = ccbGetRootSceneNode();
ccbSetSceneNodeProperty(root, "BackgroundColor", r,g,b);
ccbUnregisterOnFrameEvent( nuBGcolor );
}



just_in_case
Moderator
Quote
2022-01-10 05:38:56

Sorry, for the late response, I didn't know you were switching the scenes, yes this is a bug with CopperCube and it's an old Bug reported many times on the forums, I thought this was been fixed in the earlier version 6.0.1. In past, I myself have mentioned this bug in the past quite a few times, the bug was when you switch to a new scene the background color will remain unaffected if you have a different background color for different scenes.

here is a link to one of the posts the issue was been mentioned.
https://www.ambiera.com/forum.ph...

The method proposed by @csp-games, also deal with the background color property, so it will not work either.

The possible fix that comes to my mind is to use a solid colored skybox and then use my shader if you are working on windows exe platform to swap the color of all the materials of the skybox, with the desired color.

here is the link to the shader.
https://neophyte.cf/ccb_shader_c...

why I am suggesting using the palette swap shader, cause it will provide you the ability to change the color of the texture during runtime, without using any extra texture and you can change the color anytime you want. If you want you can also use it with the billboard thing of yours, it will save you extra resources.


VP
Guest
Quote
2022-01-10 07:38:37

Ah, thank you everyone!

Yes, sorry about that, I forgot to mention it's a v6.5 ccb file.

I had searched the forum but didn't spot the previous mention of this as an old issue.

No problem at all, at least there are a few workarounds for it.

Awesome community as usual, thanks for all the responses.




csp-games
Guest
Quote
2022-01-10 18:24:39

Oh BTW, as it's only a problem when at the beginning of the next scene, can't you just set this new bg color as the last thing you do in the old scene, just before going to the new scene?


VP
Guest
Quote
2022-01-10 19:08:11

Yes, that will probably work! Thanks for suggesting that...

"Even before, before first draw", lol.

Nice one, will add it in and delete the billboards! Cheers.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "In?ernational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact