weratius Posted October 12, 2015 Share Posted October 12, 2015 Hi! I'd like to ask you smth. guys: Have you ever tried to use a checkOverlap method, that checks whether dragging element is overlapped lying one or not. Here is the code:checkOverlap: function(spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB);}I always have bugs with that: sometimes when I'm dragging element and overlap another one this method returns false, but elements are overlapped Why does that happen? Thank you in advance) Link to comment Share on other sites More sharing options...
DonFrag Posted October 12, 2015 Share Posted October 12, 2015 we don't know what are you passing to checkOverlap Method Link to comment Share on other sites More sharing options...
weratius Posted October 12, 2015 Author Share Posted October 12, 2015 we don't know what are you passing to checkOverlap MethodI pass sprites ... Link to comment Share on other sites More sharing options...
DonFrag Posted October 13, 2015 Share Posted October 13, 2015 looks like i was not clear enough.can you show code where you use this method? Link to comment Share on other sites More sharing options...
weratius Posted October 13, 2015 Author Share Posted October 13, 2015 looks like i was not clear enough.can you show code where you use this method?I use that in the update method (sorry, I can't show whole my code, because I 7 interfaces). I just to need to remove collisions on the overlapping I just need to check whether one sprite overlaps another one or not while dragging the first one, that's all How is it better to do that? I saw another topic http://www.html5gamedevs.com/topic/6488-rectangle-collides-with-spritebody/ where the answer was to use the "body" property, but I can't do that, because my sprites have fixedToCamera property and also they can be dragged I will appreciate any help, thank you! Link to comment Share on other sites More sharing options...
Skeptron Posted October 13, 2015 Share Posted October 13, 2015 Why don't you use Arcade already implemented overlap() method? Doc : http://phaser.io/docs/2.3/Phaser.Physics.Arcade.html#overlap weratius 1 Link to comment Share on other sites More sharing options...
weratius Posted October 13, 2015 Author Share Posted October 13, 2015 Why don't you use Arcade already implemented overlap() method? Doc : http://phaser.io/docs/2.3/Phaser.Physics.Arcade.html#overlapcheckOverlap: function(a, { return game.physics.arcade.overlap(a, ;}I did smth like this But there are still problems: I'm dragging a sprite, overlapping another one, but it returns false I don't get it at all Link to comment Share on other sites More sharing options...
Skeptron Posted October 13, 2015 Share Posted October 13, 2015 If you can produce a very simple example in Phaser sandbox, or JSFiddle or whatever, we could help more. Maybe file a bug? weratius 1 Link to comment Share on other sites More sharing options...
Skeptron Posted October 13, 2015 Share Posted October 13, 2015 Please check this example. It does exactly what you're looking for : http://phaser.io/examples/v2/sprites/overlap-without-physics weratius 1 Link to comment Share on other sites More sharing options...
weratius Posted October 13, 2015 Author Share Posted October 13, 2015 Please check this example. It does exactly what you're looking for : http://phaser.io/examples/v2/sprites/overlap-without-physicsIn your example is the same that I did I have problem with overlapping, I'm dragging a sprite, overlap another one, but it still returns false I have problems that it sometimes returns false when I overlap them in console I see smth like this: false5 true2 false6 trueand so on but they are overlapped here is the code:update: function() { if(this.dragStarted) { //some code var key = // smth happens; // some code this.checkOverlapWeaponInHold(key); }},checkOverlapWeaponInHold: function(holdKey) { var weapons = this.itemsObject.items; if(weapons[holdKey] != null) { if(weapons[holdKey].item != null && weapons[holdKey].item.type == 'weapon' && this.checkOverlap(this.draggingElement, weapons[holdKey].item)) { this.weaponInHoldOveredKey = holdKey; } } },checkOverlap: function(a, { var boundsA = a.getBounds(); var boundsB = b.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB); }, stopDrag: function(currentElement) { if(this.weaponInHoldOveredKey != 0) {this.changeWeaponPlace(currentElement, this.weaponInHoldOveredKey); this.weaponInHoldOveredKey = 0; } this.dragStarted = false; this.draggingElement = {}; }, changeWeaponPlace: function(currentElement, overedKey) { console.log('overedKey = ', overedKey); var lyingElement = this.itemsObject.items[overedKey].item; //animation game.add.tween(currentElement.cameraOffset).to({ x: lyingElement.cameraOffset.x, y: lyingElement.cameraOffset.y }, 250, Phaser.Easing.Linear.None, true); game.add.tween(lyingElement.cameraOffset).to({ x: this.START_X, y: this.START_Y }, 250, Phaser.Easing.Linear.None, true);//place changingvar newObject1 = $.extend(true, {}, playerInfoObject[currentElement.key]); var newObject2 = $.extend(true, {}, playerInfoObject[overedKey]); playerInfoObject[overedKey] = $.extend(true, {}, newObject1); playerInfoObject[currentElement.key] = $.extend(true, {}, newObject2); newObject1 = {}; newObject2 = {};//flagsthis.itemsObject.items[currentElement.key].item.changed = true; this.itemsObject.items[overedKey].item.changed = true; //ajax this.sendSwapItem(currentElement.key, overedKey); } Link to comment Share on other sites More sharing options...
DonFrag Posted October 13, 2015 Share Posted October 13, 2015 could you try this?update: function() { if(this.dragStarted) { //some code var key = // smth happens; // some code this.checkOverlapWeaponInHold(key); }},checkOverlapWeaponInHold: function(holdKey) { var weapons = this.itemsObject.items; if(weapons[holdKey] != null) {console.log(weapons[holdKey].item);console.log(this.draggingElement); if(weapons[holdKey].item != null && weapons[holdKey].item.type == 'weapon' && this.draggingElement.overlap(weapons[holdKey].item) { this.weaponInHoldOveredKey = holdKey; } } },and check in both console logs:1-both ARE sprites2-the value of weapons[holdKey].item.type Link to comment Share on other sites More sharing options...
Recommended Posts