Jump to content



Recommended Posts

I have a Graphics object that I'm checking mouseover events on. When hovered over, I want the object to get larger and rotate itself, but I don't want the hitbox to change. I'm not really sure how to achieve this, because getBounds returns a rectangle and not a polygon or something like that.

Link to comment
Share on other sites

On 11/16/2019 at 5:58 PM, ivan.popelyshev said:

make a container, use your sprite as a child, and set "interactiveChildren=false" for container. Set hitArea for container as a rectangle. Animate sprite scale ( or width/height, same thing).

Sorry to be rude, but I do not know if you have gotten a notification for my message so I am quoting this

Link to comment
Share on other sites

Oh, thanks, i didnt get it!

therefore, the hitArea that I need to set needs to be rotated?

rotate container initially. if you want object to be not rotated afterwards, well, rotate it in other direction.

hitArea is measured in local coordinates :) Here's the code of hitArea that is the same as sprite:

container.rotation = Math.PI/10; // a bit

sprite.anchor.set(0.5); //usually
sprite.scale.set(...);//whatever size you want, same as sprite.width = something

container.interactiveChildren = false; // turn off sprite interaction
container.hitArea = new PIXI.Rectangle(-sprite.width/2, -sprite.height/2, sprite.width, sprite.height); //that's for anchor 0.5 and position 0.
// Your sprite local position and anchor can be different, you have to edit in that case.
// (sprite.position.x - sprite.anchor.x * sprite.width, sprite.position.y - sprite.anchor.y * sprite.height);
// also sprite.width is actually texture.width * sprite.scale.x if sprite has no children
// if it has children - you'll have a problem, use texture.width directly!


Edited by ivan.popelyshev
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.

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.


  • Recently Browsing   0 members

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