Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
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. |
||||
|
There is a fade in fade out extension somewhere on these forums |
||||
|
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); } } |
||||
|
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. |
||||
|
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. |
||||
|
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 |
|