Re: Instantiating bodies from a prototype in a RUBE document
Posted: Wed Jun 12, 2013 8:34 am
Ugh... obviously it's read and written to different b2dJson objects. My barely born C++ is failing me...
Crushing immovable objects since 2011
https://www.iforce2d.net/forums/
Code: Select all
b2dJson json;
b2dJsonImage* img = new b2dJsonImage();
img->m_body = ...;
img->m_name = ...;
img->m_file = ...;
img->m_center = ...;
img->m_angle = ...;
img->m_scale = ...;
img->m_aspectScale = ...;
img->m_flip = ...;
img->m_filter = ...;
img->m_opacity = ...;
img->m_renderOrder = ...;
img->m_colorTint[0] = ...;
img->m_colorTint[1] = ...;
img->m_colorTint[2] = ...;
img->m_colorTint[3] = ...;
float aspect = imageWidthPixels / (float)imageHeightPixels;
img->updateCorners( aspect );
img->updateUVs( aspect );
json.addImage(img);
json.writeToFile( world, filename );
Code: Select all
-(void) loadBody:(NSString*) bodyName {
b2Body *b = json.getBodyByName([bodyName UTF8String]);
Json::Value bodyValue = json.b2j(b);
b2Body *body = json.j2b2Body(m_world, bodyValue);
[self afterLoadBodyProcessing:body]; // modified from afterLoadProcessing to work for only one body