psumstr Posted November 21, 2014 Share Posted November 21, 2014 Hi Pixi experts, I'm trying to trigger a callback every time I "mousemove" over a sprite and I haven't been able to get that to work the same way "click" and "mouseover" work. I've made my sprite interactive, but the mousemove callback gets trigger anytime the mouse moves anywhere in the scene, not just over the sprite. click and mouseover events work fine. I'm just getting started with Pixi and I'm using v 2.1. Are there any steps I'm missing?var circle = new PIXI.Graphics();circle.beginFill(0xFFFFFF);circle.drawCircle(0,0,100);var circleTexture = circle.generateTexture();var circleSprite = new PIXI.Sprite(circleTexture);circleSprite.tint = 0xBEABEA;circleSprite.scale = new PIXI.Point(0.5, 0.5);circleSprite.interactive = true;circleSprite.mousemove = function(interaction) { //callback code }; Quote Link to comment Share on other sites More sharing options...
DaveSomething Posted November 26, 2014 Share Posted November 26, 2014 I think that's how it's supposed to work. Just check the position in the mouse data param to see if it's over your sprite. Quote Link to comment Share on other sites More sharing options...
psumstr Posted November 26, 2014 Author Share Posted November 26, 2014 I think that's how it's supposed to work. Just check the position in the mouse data param to see if it's over your sprite.Thanks Dave. I guess I was expecting it to work like the other events. Since my sprite is based off of a circle shape, I added the hitArea property and added the following to the mousemove callback:circleSprite.mousemove = function(interactionData) { var interactionManager = new PIXI.InteractionManager(); if(interactionManager.hitTest(this, interactionData)) { console.log("mousemove over sprite"); };};Everything is working now as expected. Quote Link to comment Share on other sites More sharing options...
Alex_Matveev Posted May 15, 2015 Share Posted May 15, 2015 circleSprite.mousemove = function(interactionData) { var interactionManager = new PIXI.InteractionManager(); if(interactionManager.hitTest(this, interactionData)) { console.log("mousemove over sprite"); };};The not work in V3. Please assist Quote Link to comment Share on other sites More sharing options...
xdiepx Posted May 15, 2015 Share Posted May 15, 2015 try var interactionManager = new PIXI.interaction.InteractionManager(renderer);It looks like hitTest has been removed. Quote Link to comment Share on other sites More sharing options...
Alex_Matveev Posted May 15, 2015 Share Posted May 15, 2015 THXBut how to trigger a callback every time I "mousemove" over a sprite (the sprite not interactive) Quote Link to comment Share on other sites More sharing options...
xdiepx Posted May 15, 2015 Share Posted May 15, 2015 I usually do something like this mySprite.on('mousedown',onPress);mySprite.on('mousedown',onRelease); function onRelease(e){ mySprite .off('mousemove',onDrag);} function onPress(e){ mySprite .on('mousemove',onDrag);} function onDrag(e){ console.log("mouse is moving")} Quote Link to comment Share on other sites More sharing options...
Alex_Matveev Posted May 15, 2015 Share Posted May 15, 2015 Yes, but the work only when mySprite is interactive object. Need trigger event over a not interactive sprite. Quote Link to comment Share on other sites More sharing options...
xdiepx Posted May 15, 2015 Share Posted May 15, 2015 What do u mean? Quote Link to comment Share on other sites More sharing options...
Alex_Matveev Posted May 15, 2015 Share Posted May 15, 2015 I usually do something like this mySprite.on('mousedown',onPress);mySprite.on('mousedown',onRelease); function onRelease(e){ mySprite .off('mousemove',onDrag);} function onPress(e){ mySprite .on('mousemove',onDrag);} function onDrag(e){ console.log("mouse is moving")}The work only if mySprite.interactive = trueNeed hitTest with any sprites Quote Link to comment Share on other sites More sharing options...
xdiepx Posted May 15, 2015 Share Posted May 15, 2015 Maybe this link will help you. http://www.html5gamedevs.com/topic/2302-hittest-in-pixi/ Quote Link to comment Share on other sites More sharing options...
Alex_Matveev Posted May 16, 2015 Share Posted May 16, 2015 http://www.html5gamedevs.com/topic/14536-hittest-in-v3/ 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.