I am having problems developing a mini-game using EaselJS with my collision detection system and I need help. The problem arises when a hero (a bitmap of a circle) collides with an object and another object stands behind the first, the hero collides with both objects, even if the second collision is blocked. Here's an explanation of the image:




The cause of the problem is very simple, even if the problem itself is not:
( ), , , . , , - .
: , , - .
javascript:
rects.forEach(function (rect) {
var nextposx = circle.x + event.delta / 1000 * xvel * 20,
nextposy = circle.y + event.delta / 1000 * yvel * 20;
if (nextposy + height(circle) > rect.y &&
nextposx + width(circle) > rect.x &&
nextposx < rect.x + rect.width &&
nextposy < rect.y + rect.height) {
if (circle.y + height(circle) < rect.y) {
cls("top");
}
if (circle.x + width(circle) < rect.x) {
cls("left");
}
if (circle.x > rect.x + rect.width) {
cls("right");
}
if (circle.y > rect.y + rect.height) {
cls("bottom");
}
}
if (nextposy < 0) {
cls("bottom");
}
if (nextposx < 0) {
cls("right");
}
if (nextposx + width(circle) > stage.canvas.width) {
cls("left");
}
if (nextposy + height(circle) > stage.canvas.height) {
cls("top");
}
});
JSFiddle