Page 1 of 1

[Tutorials]use rube whit cocos2d or cocos2d-x

Posted: Thu Mar 07, 2013 3:29 pm
by qq200600

Code: Select all

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);

if you do this, you can run the images.json nicely. note: the image1's center must as same as the image1Body's position.


If you want to look the picture what i deal with, please link : http://blog.csdn.net/qq634416025/articl ... ls/8648758