Adding segments dynamically

Posts that don't fit into other categories.
jojoofu
Posts: 3
Joined: Thu Mar 23, 2017 10:31 am

Adding segments dynamically

Postby jojoofu » Fri Mar 31, 2017 1:06 pm

I'm building a terrain editing tool. I want to add a new link starting from the last link end point each time the user clicks a button.

Here is my code.

Code: Select all

                   int i = selectedEntity.body.getFixtureCount() - 1;
                   Link temp = (Link)selectedEntity.body.getFixture(i).getShape();
                   start.set(temp.getPoint2());
                   end.set(core.mouse.location);
              Link newLink = new Link( start , end );
                   newLink.setPrevious(temp);
                   selectedEntity.body.addFixture(newLink);


I get the last point. Then I set it to a vector2 start then my end point which is the mouse location I set to vector2 end. I made sure to add the previous link. Then I add it to the body.

This will add a new segment starting from the last point but each time I add another the previous segment will disappear. What part of the dots am I not connecting here ?

William
Site Admin
Posts: 351
Joined: Sat Feb 06, 2010 10:23 pm

Re: Adding segments dynamically

Postby William » Sat Apr 01, 2017 10:00 am

I'm not sure what the problem here is. It seems to be working as expected for me. Perhaps there's something else going on in your code?

What other details can you supply? Can you replicate outside of your app?

William

jojoofu
Posts: 3
Joined: Thu Mar 23, 2017 10:31 am

Re: Adding segments dynamically

Postby jojoofu » Sat Apr 01, 2017 4:20 pm

I ended up just doing it a different way. I made an array of points and rebuilt the shape each time a point was added or removed. Not quite as efficient but a lot easier to manage.

The error I was getting before was a segment must have two different points. It was because when I was adding a line at mouse click the next preview point was added immediately on top of it. I just added .01 to mouse location value to make the number different.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests