Seby Posted June 28, 2013 Share Posted June 28, 2013 Hi, I think i've found a new mini bug This code doesn't work : var graphics = new PIXI.Graphics(); graphics.beginFill(0xFFFF00); // set the line style to have a width of 5 and set the color to red graphics.lineStyle(5, 0xFF0000); // draw a rectangle graphics.drawRect(100, 150, 50, 50); // make the button interactive.. graphics.setInteractive(true); graphics.click = function(data){ console.log('hit rect'); } But this... work correctly var graphics = new PIXI.Sprite(textureButton); graphics.position.x = 100; graphics.position.y = 100; // make the button interactive.. graphics.setInteractive(true); graphics.click = function(data){ console.log('hit rect'); } Quote Link to comment Share on other sites More sharing options...
enpu Posted June 28, 2013 Share Posted June 28, 2013 Yeah you have to define hitArea manually for PIXI.Graphics graphics.hitArea = new PIXI.Rectangle(100, 150, 50, 50); Quote Link to comment Share on other sites More sharing options...
Seby Posted June 28, 2013 Author Share Posted June 28, 2013 Oh yeah Thanks Enpu Quote Link to comment Share on other sites More sharing options...
poshaughnessy Posted January 9, 2015 Share Posted January 9, 2015 Thanks for this! Just to add, in case it saves anyone a minute or two of confusion, nowadays you do:graphics.interactive = true;Instead of:graphics.setInteractive(true); Quote Link to comment Share on other sites More sharing options...
JDW Posted January 12, 2015 Share Posted January 12, 2015 Small but useful trick to set hitArea for rectangle graphics : graphics.hitArea = graphics.getBounds(); sitnarf 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.