schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 329 forks source link

Change Shape on the fly? #125

Closed MarkusTieche closed 10 years ago

MarkusTieche commented 10 years ago

Is it possible to change simple shapes on the fly? change_shape

Something like, create a poly shape with shape.body.addPolygon({}, polyShape);, just a regular poly which represents a rectangle. Access the points later on, manipulate and update them. Is this possible? And do you think it would decrease Ram usage and garbage collection by reusing simple shapes, instead of recreating them each time? Just like an object pool?

schteppe commented 10 years ago

You should be able to use the same shape. You need to update the bounding geometry and other internal shape properties though. See http://www.html5gamedevs.com/topic/5692-p2-increase-body-radius-over-time/

MarkusTieche commented 10 years ago

Thanks for your help, tested and works. Here the fiddle

http://jsfiddle.net/inkfood/u7TC4/

Thanks for all the work and effort you put into this physics engine, just to let you know.

schteppe commented 10 years ago

Cool!