Jump to content

Multiple primitives (rects) and events


tet
 Share

Recommended Posts

Great community! 

 

I just started playing around with pixi and have drawn multiple rectangles from an array with pixel coordinates like this:

 

 
var rectangle = [....];....var stage = new PIXI.Stage();var renderer = PIXI.autoDetectRenderer(wrapper.getWidth(), wrapper.getHeight(), { transparent: true });....var graphics = new PIXI.Graphics();graphics.interactive = true;graphics.on("mouseover", function(e) {   this.alpha = 0.5;}).on("mouseout", function() {   this.alpha = 1;});graphics.beginFill(0xFFFFFF);graphics.lineStyle(2, 0x000000);for (var i = 0; i < rectangle.length; i++) {   graphics.drawRect(rectangle[i][0], rectangle[i][1], 10, 10);}graphics.endFill();stage.addChild(graphics);renderer.render(stage);

The events are triggered but the object I get by "e" or "this" inside the callback is the object for all graphics. I want to get that single rectangles object I can see in the graphicsData, but there is no id or anything for me to identify it by. How can I do this?

 

Performance is of essence as I'm going to render 20k+ rectangles or circles.

 

 

 

edit: cleaned up code block and line breaks.

Link to comment
Share on other sites

> I want to get that single rectangles object I can see in the graphicsData, but there is no id or anything for me to identify it by. How can I do this?

 

The concept of shapes inside of a graphics object doesn't really exist. graphicsData is internally used for drawing the paths, but you can't "get" a specific rectangle in a graphics object that draws many rectangles.

Link to comment
Share on other sites

Okay. Do you have any suggestions on how I could achieve mouse events for the 20k+ primitives with good performance that would give information on what primitive was hovered, clicked etc?

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...