i've some problems with craftyjs, collision and polygons.
Here is my code: http://jsfiddle.net/haenx/85mhj/
As you can see, the player will hit the enemy each time both boxes are overlapping. But the given polygon has another form and it semms it will be ignored...
I can't figure out, why. The docs from craftys are also not the best.
Crafty.init(300,300, document.querySelector('#Game'));
Crafty.e('2D, Canvas, Color, Mouse')
.attr({
x: 0,
y: 0,
w: 300,
h: 300
})
.color('#333')
.bind('MouseMove', function () {
player.x = Crafty.mousePos.x - (32 / 2);
player.y = Crafty.mousePos.y - (32 / 2);
});
Crafty.c('Enemy', {
init: function () {
this
.addComponent('2D, Canvas, Color')
.attr({
x: 134,
y: 134,
w: 32,
h: 32
})
.color('#ff0');
}
})
var enemy = Crafty.e('Enemy');
var player = Crafty.e('2D, Canvas, Color, Collision, WiredHitBox')
.attr({
x: 134,
y: 134,
w: 32,
h: 32
})
.color('#f00');
player
.collision(new Crafty.polygon([0,0], [0,6], [8, 13], [24,13], [32,6], [32,0]))
.onHit('Enemy',
function() {
enemy.color('#fff');
},
function() {
enemy.color('#ff0');
}
);