ForgeableSum Posted June 12, 2015 Share Posted June 12, 2015 Suppose I have an area of the game users can click and something happens. The area is not defined by a visible object. It doesn't have a texture like a sprite of image object would. That said, what sort of object should I use to create my area? It needs to have height/width, x/y and receive input events but it doesn't need a texture. Even though Phaser.Rectangle would be ideal, geometry isn't an option because geometry doesn't have events. Unless there is a way to attach input events to geom? Sprite and image isn't an option because it must have a texture. I could use a fake texture but I am looking to use an object that is as lightweight as possible as there will be a lot of these areas receiving input events. Link to comment Share on other sites More sharing options...
XekeDeath Posted June 12, 2015 Share Posted June 12, 2015 You are slightly mistaken about Phaser.Image and Phaser.Sprite. They do not require a texture.I use invisible images all the time. Simply do not pass it anyting after the position, and you can adjust the width and height as much as you like after that. This is taken from my current project, where I wanted to prevent all input passing below a certain level in the draw order:this.eatMe = new Phaser.Image(this.game, 0, 0);this.eatMe.inputEnabled = true;this.eatMe.width = this.game.width;this.eatMe.height = this.game.height;this.eatMe.events.onInputDown.add(function(){}, this);this.add(this.eatMe);This Phaser.Image eats all inputs, hence the name, and does nothing with them... Link to comment Share on other sites More sharing options...
ForgeableSum Posted June 12, 2015 Author Share Posted June 12, 2015 neat. do you think this (image without texture) is more lightweight than a graphics object with a hit area? Link to comment Share on other sites More sharing options...
brejep Posted June 12, 2015 Share Posted June 12, 2015 You could use a rectangle:this.game.input.onDown.add(function(pointer) { if(Phaser.Rectangle.containsPoint(hitAreaRectangle, pointer.position)) { // do something }});The event is on game.input but you could use your rectangle geometry to hit test the pointer and then execute whatever behaviour is meant to happen. Link to comment Share on other sites More sharing options...
Recommended Posts