Scene transitions

231 views
Skip to first unread message

RedHickory Creative

unread,
Apr 2, 2012, 1:34:52 AM4/2/12
to craf...@googlegroups.com
I'm a bit of a newbie to Crafty and I was looking for a way to do visual transitions between scenes.  I couldn't find anything in the docs so I wrote this up:

function load_scene(scene, duration) {
    Crafty.e("2D, Canvas, Tween, Color")
        .attr({alpha:0.0, x:0, y:0, w:800, h:600})
        .color("#000000")
        .tween({alpha: 1.0}, duration)
        .bind("TweenEnd", function() {
            Crafty.scene(scene);
            Crafty.e("2D, Canvas, Tween, Color")
                .attr({alpha:1.0, x:0, y:0, w:800, h:600})
                .color("#000000")
                .tween({alpha: 0.0}, duration);
        });
}

It fades to black, loads the new scene, then fades back to transparent.  It seems to work on the limited testing I have done.  Just thought I would throw it out there in case anyone else needs something like this while this feature is (hopefully) being developed.

Louis Stowasser

unread,
Apr 2, 2012, 1:36:03 AM4/2/12
to craf...@googlegroups.com
Very nice!

I would recommend making it a module and submitting to  http://craftycomponents.com/ 

Cheers!

Lab Monkey

unread,
May 24, 2013, 9:57:06 AM5/24/13
to craf...@googlegroups.com
Really nice, I'm adding this to the community cookbook! I'll give you full credit :)
Reply all
Reply to author
Forward
0 new messages