now while the drag event is workiing (i can trag an item around) i want that something happens, when the basket in this code collides with another item (bananaGroup)
I am not sure how to get this done and tried this. As you can see i want the basket changes it color when the item banana hits it and the game to pause.
this.physics.add.collider(bananaGroup, this.basket, this.hitBasket);
}
update() {
// everything that is constantly checked
//kommentar hier
}
hitBasket()
{
this.physics.pause();
this.basket.setTint(0xff0000);
console.log("stop")
};
This is actually quite difficult, because the body velocity is not set when dragging. The (arcade) physics engine doesn’t do collisions without velocity. So use overlap, maybe even without physics, like so:
First of, you don’t need any of the gfx stuff. You only need RectangleToRectangle.
Try it without doing this
No. You’ll have to check for each sprite in the group.
overlap.setEmpty(); // Clear the Rectangle, since GetRectangleIntersection doesn't clear it.
GetRectangleIntersection(rect1, rect2, overlap);
if (!overlap.isEmpty()) { // If there is an overlap, draw the overlap rectangle.
gfx.strokeRectShape(overlap);
}
i am not sure where the rectangle gets the data that it is as big as the Eye IMG but i think thats one thing Geom does.
As for the best solution here:
When i want colliders behind my Images (like circles and stuff) that actually collide and do something (like i your example). Is it better to use .graphics or Geom?
It depends on what you call collision. It registers overlap, but there is no physics ‘reaction’. So no ‘air hockey’, by dragging your sprite very fast against an other sprite, because there is no velocity…