Checking overlap between two sprites can be done without enabling physics for them.
Code:
"use strict"; window.Overlap.state.menu = { create: function() { //create both objects and allow them to be dragged across the map this.box = mt.create("box_simple"); this.box.inputEnabled = true; this.box.input.enableDrag(); this.grass = mt.create("grass"); this.grass.inputEnabled = true; this.grass.input.enableDrag(); this.text = mt.create("Text"); }, update: function() { //checks, if the overlap function returns true and acts accordingly if (this.checkOverlap(this.box, this.grass)) { this.text.setText('Yay!'); } else { this.text.setText(''); } }, //gets bounds form both sprites and returns true, if they intersect each other checkOverlap: function(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB); } };
Mouse drag any sprite over the other.
Full sample available here.
is that possible to make not overlapping if you know please help me in this .
thanks
Gopi R
If we compare this with the physics based collision, which one would be more efficient ?
This really is literally the best thing I’ve study this week!
Just like, https://kultourinbaden.ch/ did of which in my opinion last few days, but that article has certainly manufactured my day very much better.
Thank you for so much exclusive and insightful information, always!