Bind Click-Event to whole Canvas?

465 views
Skip to first unread message

Mark Kalder

unread,
Feb 17, 2012, 3:01:16 PM2/17/12
to craf...@googlegroups.com
Hi,

is it anyhow possible to bind a Click- or mouseOver-Event to the Canvas/Scene?
I cant realy get it to work like this or so:
Crafty.canvas.bind("Click", function(e) {
console.log(arguments);
// this.tween({alpha: 0.0}, 50);
// this.antigravity();
});

witali mik

unread,
Feb 17, 2012, 4:01:51 PM2/17/12
to craf...@googlegroups.com
Crafty.addEvent

here an example http://craftyjs.com/demos/isometric/game.js

Mark Kalder

unread,
Feb 21, 2012, 12:35:25 PM2/21/12
to craf...@googlegroups.com
Doesn't seem to work. I just added this code to my scene:
Crafty.addEvent(this, Crafty.stage.elem, "mouseDown", function(e) {
console.log("mouseDown");
// Crafty.addEvent(this, Crafty.stage.elem, "mouseMove", scroll);
// Crafty.addEvent(this, Crafty.stage.elem, "mouseUp", function() {
// Crafty.removeEvent(this, Crafty.stage.elem, "mouseMove", scroll);
// });
});

Matt Petrovic

unread,
Feb 21, 2012, 12:49:17 PM2/21/12
to craf...@googlegroups.com
addEvent is for DOM events. It would need to be "mousedown". 

Mark Kalder

unread,
Feb 21, 2012, 1:00:53 PM2/21/12
to craf...@googlegroups.com
Thanks alot! It works!
Message has been deleted
Message has been deleted

Алексей Буряков

unread,
Oct 18, 2012, 10:16:59 AM10/18/12
to craf...@googlegroups.com
But, can I do this with canvas, not with DOM?
When I'm trying to bind event to canvas I got an error:
Crafty.canvas.bind is not a function

Matt Petrovic

unread,
Oct 18, 2012, 10:20:50 AM10/18/12
to craf...@googlegroups.com
Please read the thread. Your question was answered. The canvas still uses DOM events.

Алексей Буряков

unread,
Oct 18, 2012, 10:39:12 AM10/18/12
to craf...@googlegroups.com, mpet...@guneva.net
Uh, checked my code again and all works now, thank you!
Reply all
Reply to author
Forward
0 new messages