Skip to main content
Participating Frequently
June 17, 2022
Question

Snow show on YouTube in animate cc canvas.

  • June 17, 2022
  • 1 reply
  • 161 views

Hello everyone on the forum.
I saw a very nice show on youtube.

Here is the link.

https://www.youtube.com/watch?v=4p9etJ5GHS0

Maybe someone will explain to me why this code does not work for me.
Snow appears on the stage, but everything stands still.
There is no error in the console.
Here's the code.


var sh = stage.canvas.height*2;
var sw = stage.canvas.width*2;
var snowcontainer = new createjs.Container();
snowcontainer.regX = sw/2;
this.addChild(snowcontainer);

function randomize(min, max) {
return (Math.random() * max) + min; //return Math.round(Math.random() * max) + min;
}

createjs.Ticker.on("tick", snowfall);

function snowfall(e) {
for (var i = snowcontainer.numchildren-1; i >=0; i--){
var s = snowcontainer.getChildAt(i);
s.y += s.speed;
if (s.y > sh+20) {
s.y = randomize(-500, sh);
}
}
}

function snowstrom(sfc) {
for (var i = sfc; i >= 0; i--) {
var sf = new lib.snowflake();
sf.x = randomize(0, sw);
sf.y = randomize(-500, sh);
sf.alpha = randomize(0.5, 0.9);
sf.scaleX = randomize(0.5, 0.9);
sf.scaleY = sf.scaleX;
sf.speed = randomize(1, 8);
snowcontainer.addChild(sf);
}
}
snowstrom(1000);


Regards

    This topic has been closed for replies.

    1 reply

    JoãoCésar17023019
    Community Expert
    Community Expert
    June 17, 2022

    Hi.

     

    It's because you wrote numchildren (with lowercase c). The correct is to write numChildren (with a capital C).

     

    So instead of:

    for (var i = snowcontainer.numchildren - 1; i >= 0; i--)

     

    It must be:

    for (var i = snowcontainer.numChildren - 1; i >= 0; i--)

     

    I hope it helps.

     

    Regards,

    JC

    Participating Frequently
    June 17, 2022

    Welcome back

    Thank you very much, it works.
    Man learns all his life.
    Thank you again and best regards.

    Jan

    JoãoCésar17023019
    Community Expert
    Community Expert
    June 17, 2022

    You're welcome.