driiper Posted March 5, 2015 Share Posted March 5, 2015 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. 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 Quote Link to comment Share on other sites More sharing options...
driiper Posted March 8, 2015 Author Share Posted March 8, 2015 Anyone? Edit: Reason for this happening is that the hitArea is relative to the sprite position. In my case, the hitArea was using absolute coordinates, hence yielding this result. Thanks to englercj for assistance. Driiper 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.