Skip to main content
Participating Frequently
Jun 17, 2022 6:09 AM UTC
Question

Snow show on YouTube in animate cc canvas.

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 is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    Jun 17, 2022 9:57 AM UTC

    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

    Translate
    Participating Frequently
    Jun 17, 2022 8:08 PM UTC

    Welcome back

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

    Jan

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Jun 17, 2022 8:16 PM UTC

    You're welcome.

    Translate