spinnerbox Posted August 29, 2016 Share Posted August 29, 2016 Damn I have buggy code Trying to check if mouse points x/y position is in bounds of a given graphics object called leftShelveGraphics. I do this: gameObject.physics.enable(leftWallGraphics, phaser.Physics.ARCADE); update: function () { console.log(leftWallGraphics.getBounds().x + ", " + leftWallGraphics.getBounds().y + ", " + leftWallGraphics.getBounds().width + ", " + leftWallGraphics.getBounds().height + ", " + horzBaffleObj.x + ", " + horzBaffleObj.y); if (phaser.Rectangle.contains(leftWallGraphics.getBounds(), horzBaffleObj.x, horzBaffleObj.y)) { console.log("I am over leftWallGraphics"); } } But the above console.log() prints 0,0,0,0 for x/y/width/height. horzBaffle.x/y are actual values of the object I move on update. Am i missing to set up something? leftShelveGraphics contains other graphical shapes like polygons, rectangles, and more complex graphics like shelves. EDIT: leftShelveGraphics is child of larger container graphics object called constrGrObject which is child of gameObject.world. Could this be causing some issues? Link to comment Share on other sites More sharing options...
spinnerbox Posted August 29, 2016 Author Share Posted August 29, 2016 getBounds() doesn't work if it is a composite graphics object? Link to comment Share on other sites More sharing options...
spinnerbox Posted August 29, 2016 Author Share Posted August 29, 2016 Well I guess so. I had to access sub objects to test if bounds contain certain point: update: function () { if (utils.isTruthy(horzBaffleObj)) { if (gameObject.input.mousePointer.isDown) { horzBaffleObj.x = gameObject.input.mousePointer.x; horzBaffleObj.y = gameObject.input.mousePointer.y; if (leftShelveGraphics.getChildAt(0).getBounds().contains(horzBaffleObj.x, horzBaffleObj.y) || leftShelveGraphics.getChildAt(1).getBounds().contains(horzBaffleObj.x, horzBaffleObj.y)) { console.log("I am over leftShelveGraphics"); } if (rightShelveGraphics.getChildAt(0).getBounds().contains(horzBaffleObj.x, horzBaffleObj.y) || rightShelveGraphics.getChildAt(1).getBounds().contains(horzBaffleObj.x, horzBaffleObj.y)) { console.log("I am over rightShelveGraphics"); } } else { horzBaffleObj.destroy(); } } }, Link to comment Share on other sites More sharing options...
Recommended Posts