Crafty.init();
Crafty.modules("http://cdn.craftycomponents.com/", {
hexmap: '0.2'
}, function() {
Crafty.sprite(64, "http://bobusumisu.net/wp-content/uploads/2012/01/hexagons.png", {
path: [0, 0],
hexagon: [1, 0],
selected: [2, 0]
});
var hexmap = Crafty.e("Hexmap").hexmap(64, 64);
var selected = null;
var path = null;
hexmap.create(10, 10, function() {
return Crafty.e("2D, DOM, Mouse, hexagon").bind("Click", function() {
if (!selected) {
selected = this;
this.removeComponent("hexagon").addComponent("selected");
}
else if (selected === this) {
selected = null;
this.removeComponent("selected").addComponent("hexagon");
}
}).bind("MouseOver", function() {
if (selected) {
if (path) path.forEach(function(tile) {
tile.removeComponent("path").addComponent("hexagon");
});
path = hexmap.findPath(selected, this);
if (path) path.forEach(function(tile) {
tile.removeComponent("hexagon").addComponent("path");
});
}
});
});
});
External resources loaded into this fiddle: