Jump to content

HitArea on Sprite, Not positioned correctly?


driiper
 Share

Recommended Posts

Hello!

 

I'm trying to add a HitArea to a sprite, but the hitArea appears below the sprite itself, Ive used the same hitArea on an Graphics element with a polygon, and it works fine.

 

9965cc37d7162f4acb4f311904f6d1cb.gif

 

What you see here is an representation of the problem.

 

I draw both the Graphic elements and the Sprite element, and they are positioned correctly. I then add the hitarea to both the Graphics and the Sprite using the polygon bounds.

As you can see, it does light up as expected when hovering an object (Graphics object trigger), but the Sprite only triggers when i hover slightly below the Sprite. 

What is causing this?

 

Code for drawing Graphics and Sprite objects:

      # GRAPHICS PRIMITE EDITION      # Set bound padding to 0      graphics.boundsPadding = 0      mapContainer.addChild graphics      # Hovering the graphics object      graphics.mouseover =  (e) ->        this.clear()        this.lineStyle(2, 0x000000, 1);        #this.blendMode = PIXI.blendModes.ADD        this.beginFill(0xffffff, 1);        this.drawPolygon(this.polygon.points)      # leave hovering the graphics object      graphics.mouseout =  (e) ->        this.clear()        this.lineStyle(2, 0x000000, 1);        this.beginFill(0xffffff, 0.5);        this.blendMode = 0        this.drawPolygon(this.polygon.points)      # SPRITE EDITION      # Generate a normal texture      texture = graphics.generateTexture()      # Generate a hover texture      graphics.clear()      graphics.lineStyle(3, 0xFF0000, 1);      graphics.blendMode = PIXI.blendModes.ADD      graphics.drawPolygon(graphics.polygon.points)      hoverTexture = graphics.generateTexture()      # Create a sprite      sprite = new Gotham.Graphics.Sprite texture      sprite.normalTexture = texture      sprite.hoverTexture = hoverTexture      sprite.position.x = graphics.minX      sprite.position.y = graphics.minY      hitarea = new PIXI.Polygon graphics.polygon.points      sprite.hitArea = hitarea      sprite.interactive = true      mapContainer.addChild sprite      # Hovering the graphics object      sprite.mouseover =  (e) ->        @bringToFront()        @texture = @hoverTexture      sprite.mouseout =  (e) ->        @texture = @normalTexture
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...