spinnerbox Posted September 16, 2016 Share Posted September 16, 2016 I have this utility function: var geoObjContainsPt = function (geoObj, x, y) { return geoObj.getBounds().contains(x, y); } When I use it with sprite type of object it does not work in all cases. Maybe the bug is elsewhere but as I checked the docs, Phaser.Sprite.getBounds() wants Sprite's transformation matrix. I guess that is coordinate transformation matrix. Not sure. But how can I get it? Some connection with worldTransform. What is that? Or should I use getLocalBounds()? Note: On the contrary Phaser.Graphics.getBounds() does not need a parameter. http://phaser.io/docs/2.6.2/Phaser.Sprite.html#getBounds http://phaser.io/docs/2.6.2/Phaser.Graphics.html#getBounds Only certain sprites get tinted with green. Some sort of a pattern haha jamespierce 1 Link to comment Share on other sites More sharing options...
spinnerbox Posted September 16, 2016 Author Share Posted September 16, 2016 Tried this sort of thing. Its the same result: var spriteContainsPt = function (geoObj, x, y, frameX, frameY) { var matrix = new Phaser.Matrix(1, 0, 0, 1, frameX, frameY); return geoObj.getBounds(matrix.translate(x, y)).contains(x, y); }; But ok, I add the sprites inside a Phaser.Graphics object so when i get them with tileContainerGraphics.children It returns array of DisplayObject objects. Does this changes something? EDIT: DisplayObject does not have getBounds() function Link to comment Share on other sites More sharing options...
spinnerbox Posted September 16, 2016 Author Share Posted September 16, 2016 Lost whole day just to find out that my indexes were not calculated correctly. I am translating two dimensional array indexes to a one dimensional array index. Both arrays have the same amount of elements. I created my own utility function. Something like: var convertTwoDimIndexesToOneDimIndex = function (cols, currentRow, currentCol) { return currentCol + cols * currentRow; }; jamespierce 1 Link to comment Share on other sites More sharing options...
Recommended Posts