Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Object Fade

jdw6701
Registered User
Quote
2020-02-05 16:48:18

I'm trying to make a object in my scene fade into view after the scene itself fades in, but as usual, Coppercube doesn't have that option.

Could someone help a brother out and find a solution, cause if a 3D engine can't do something that Scratch, a child's play 2D engine, has built in, that's kinda sad.


Zoo
Guest
Quote
2020-02-07 22:44:32

There is a fade in fade out extension somewhere on these forums


Robo
Guest
Quote
2020-02-08 06:38:05

this is the extension code:

// This is a scripted coppercube action.

// It fades the whole screen to or from black, and executes an action after finished.

//
// The following embedded xml is for the editor and describes how the action can be edited:

// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action


/*

<action jsname="action_FadeScreen" description="Fade the whole screen">

<property name="TimeToFade" type="int" default="500" />

<property name="Color" type="color" default="ff000000" />

<property name="FadeOut" type="bool" default="true" />

<property name="ActionWhenFinished" type="action" />

</action>

*/



action_FadeScreen = function()
{
};


// called when the action is executed
action_FadeScreen.prototype.execute = function(currentNode)


{
var me = this;

this.registeredFunction = function()
{ me.drawFadeScreenFunc();
};


ccbRegisterOnFrameEvent(this.registeredFunction);
this.startTime = (new Date()).getTime();

this.endTime = this.startTime + this.TimeToFade;


this.currentNode = currentNode;

}



// --------------------------------------------------------

// Implementation of the screen fading function



action_FadeScreen.prototype.drawFadeScreenFunc = function()


{
var me = this;


var now = (new Date()).getTime();

// calculate color


var alpha = (now - me.startTime) / (me.endTime - me.startTime);

alpha = alpha * 255.0;

if (alpha > 255) alpha = 255;

if (alpha < 0) alpha = 0;

if (!me.FadeOut) alpha = 255 - alpha;

var color = (alpha<<24) | (me.Color & 0x00ffffff);

// draw rectangle



ccbDrawColoredRectangle(color, 0, 0, ccbGetScreenWidth(), ccbGetScreenHeight());

// stop fading if end reached and run an action


if (now > me.endTime)

{

ccbUnregisterOnFrameEvent(this.registeredFunction);

ccbInvokeAction(me.ActionWhenFinished, me.currentNode);

}

}


jdw6701
Registered User
Quote
2020-02-11 20:10:01

Robo wrote:
this is the extension code:

// This is a scripted coppercube action.

// It fades the whole screen to or from black, and executes an action after finished.

//
// The following embedded xml is for the editor and describes how the action can be edited:

// Supported types are: int, float, string, bool, color, vect3d, scenenode, texture, action


/*

<action jsname="action_FadeScreen" description="Fade the whole screen">

<property name="TimeToFade" type="int" default="500" />

<property name="Color" type="color" default="ff000000" />

<property name="FadeOut" type="bool" default="true" />

<property name="ActionWhenFinished" type="action" />

</action>

*/



action_FadeScreen = function()
{
};


// called when the action is executed
action_FadeScreen.prototype.execute = function(currentNode)


{
var me = this;

this.registeredFunction = function()
{ me.drawFadeScreenFunc();
};


ccbRegisterOnFrameEvent(this.registeredFunction);
this.startTime = (new Date()).getTime();

this.endTime = this.startTime + this.TimeToFade;


this.currentNode = currentNode;

}



// --------------------------------------------------------

// Implementation of the screen fading function



action_FadeScreen.prototype.drawFadeScreenFunc = function()


{
var me = this;


var now = (new Date()).getTime();

// calculate color


var alpha = (now - me.startTime) / (me.endTime - me.startTime);

alpha = alpha * 255.0;

if (alpha > 255) alpha = 255;

if (alpha < 0) alpha = 0;

if (!me.FadeOut) alpha = 255 - alpha;

var color = (alpha<<24) | (me.Color & 0x00ffffff);

// draw rectangle



ccbDrawColoredRectangle(color, 0, 0, ccbGetScreenWidth(), ccbGetScreenHeight());

// stop fading if end reached and run an action


if (now > me.endTime)

{

ccbUnregisterOnFrameEvent(this.registeredFunction);

ccbInvokeAction(me.ActionWhenFinished, me.currentNode);

}

}




I'm trying to only fade one specific node, not the whole scene.


Robo
Guest
Quote
2020-02-13 09:14:43

Ok, well fading in instead of just switching on....interesting idea but sounds difficult.
What about using dynamic textures to change the png semi transparent texture over time ?

Or add a transparent texture and play with the black color emissive to go darker over time. Maybe that would work.

There is code on the forum how to do that, see announcements.


jdw6701
Registered User
Quote
2020-02-18 13:49:49

Robo wrote:
Ok, well fading in instead of just switching on....interesting idea but sounds difficult.
What about using dynamic textures to change the png semi transparent texture over time ?

Or add a transparent texture and play with the black color emissive to go darker over time. Maybe that would work.

There is code on the forum how to do that, see announcements.



i'll give it a try


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (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