Jump to content

Mousemove on Sprites


psumstr
 Share

Recommended Posts

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 };
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 5 months later...

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")

}

Link to comment
Share on other sites

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 = true

Need hitTest with any sprites

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...