cocos2d-x用rube box2d editor当关卡编辑器写游戏

转载请说明出处:http://blog.csdn.net/qq634416025/article/details/8648758

转载请说明出处:http://blog.csdn.net/qq634416025/article/details/8648758

std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("images.json");
   unsigned long size;
   unsigned char *file = CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "rt+", &size);
   std::string str = "";
   for (int i = 0; i < size; i++)
   {
      str += file[i];
   }
   std::string error;
   b2dJson json;
   world = json.readFromString(str, error);

b2dJsonImage *image1_ = json.getImageByName("image1");

CCSprite *image1 = CCSprite::create("images/mcclory.png");
image1->setScale((image1_->scale * PTM_RATIO)/ image1->getTexture()->getPixelsHigh());

image1Body->SetUserData(image1);

this->addChild(image1, 0);

注意在编辑的时候 图片的中心一定要和刚体的位置重合

cocos2d-x用rube box2d editor当关卡编辑器写游戏_第1张图片cocos2d-x用rube box2d editor当关卡编辑器写游戏_第2张图片

软件地址:https://www.iforce2d.net/rube/

你可能感兴趣的:(editor,cocos2d-x,box2D,rube)