Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Help with 2D animation please

veganpete
Registered User
Quote
2020-09-17 00:18:58

[SOLVED] I've learned to successfully animate 2D using "2D overlays" or with "Animated Billboards" in coppercube6.

My problem is with the 2D billboard animations. I used "animate a texture" and they look great - but because they loop, I can't make the animation start at frame 1 when I make the billboard visible - it's already part way through the animation (the animation plays while the billboard is invisible).

My question is: How do I get a billboard animation to start/restart when the billboard is made visible?

Would cloning the billboard force it to restart the animation - or any other ideas please?

Thank you.


Robo
Guest
Quote
2020-09-17 08:31:05

You could try using and adjusting a behavior to do the same thing - maybe add a variable that gets updated at certain times, or just code it all yourself into javascript directly:

// This is a coppercube behavior for animating the texture of an 3D object, with a set of dynamically loaded textures.
// Note that the texture files need to be on the same server as your 3D scene, otherwise they cannot be loaded.
//
// 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
/*
<behavior jsname="behavior_AnimateDynamicLoadedTextures" description="Animate with dynamically loaded textures">
<property name="TimePerFrame" type="int" default="200" />
<property name="MaterialIndex" type="int" default="0" />
<property name="TextureAmount" type="int" default="8" />
<property name="StartTextureIndex" type="int" default="1" />
<property name="URL" type="string" default="texture$NUMBER$.png" />
</behavior>
*/


behavior_AnimateDynamicLoadedTextures = function() {
this.StartTime = null;
}

behavior_AnimateDynamicLoadedTextures.prototype.onAnimate = function(node, timeMs) {
if (this.StartTime == null)
this.StartTime = timeMs;
var idx = this.StartTextureIndex + (Math.floor((timeMs - this.StartTime) / this.TimePerFrame) % this.TextureAmount);
ccbSetSceneNodeMaterialProperty(node, this.MaterialIndex, "Texture1", ccbLoadTexture(this.URL.split("$NUMBER$").join(idx.toString())));
}


veganpete
Registered User
Quote
2020-10-02 23:05:49

Thanks!

I finally got it to work by manually triggering all the frames with a time delay. eg:

Billboard_Animation_1:
do something later 20ms set texture "frame 1"
do something later 40ms set texture "frame 2"
do something later 60ms set texture "frame 3"
do something later 80ms set texture "frame 3"
....etc


just_in_case
Moderator
Quote
2020-10-05 08:34:29

I am not sure about this but maybe restarting behaviours of a scenenode would have reset the behaviors of the scenenode and the animation would have started from frame 1..... You don't have to add that much do something later action....

Just give it a try with animated a texture behavior, and use restart behaviours of a scenenode action... I think it might reset the animation frame as well...

Hope that helps... And will require less effort while doing stuff like this..😇


veganpete
Registered User
Quote
2020-10-12 09:03:56

Boom! Nice suggestion - thanks! I'll give it a try and comment here.

Hopefully it will work; if it does, it will make 2D animation so much easier in the future. Thank you!


veganpete
Registered User
Quote
2020-10-12 23:16:34

Just to confirm "reset behaviour" does work. It successfully restarts a texture animation from the beginning.

Thanks again for the suggestion!


just_in_case
Moderator
Quote
2020-10-13 10:35:13

Glad that it worked for you


Create reply:


Posted by: (you are not logged in)


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