Exemple #1
0
void MapCell::updateView(const char *mapName, const Size &gridScale)
{
	int x = ((int)gloabIndex.x < 0 ? 0 : (int)gloabIndex.x);
	int y = ((int)gloabIndex.y < 0 ? 0 : (int)gloabIndex.y);

	String urlMapName;
	urlMapName.initWithFormat("%s%s/", url.c_str(), mapName);
	request->setUrl(urlMapName.getCString(), NULL);
	// 根据全局索引设置sprite
	String miniName;
	miniName.initWithFormat("MiniMaps/%s.png", mapName);
	Texture2D * texture = TextureCache::getInstance()->addImage(miniName.getCString());
	Rect rect(gloabIndex.x * 32, texture->getContentSize().height - (gloabIndex.y + 1)* 32, 32, 32);

	int heightGird = texture->getContentSize().height * 8 / 256;
	int widthGird = texture->getContentSize().width * 8 / 256;
	
	CCString fileName;

	if (x >= 0 && y >= 0 && x <= widthGird - 1 && y <= heightGird - 1)
	{
		sprite = Sprite::createWithTexture(texture, rect);
		this->addChild(sprite);
		sprite->setAnchorPoint(ccp(0, 0));
		sprite->setScaleX(gridScale.width); // 宽
		sprite->setScaleY(gridScale.height);// 高
		CCString str;
		str.appendWithFormat("LOGING %u %u", y, x);
		fileName.appendWithFormat("%u_%u.png", x, y);
		int index = x + (heightGird - y - 1) * widthGird;
		fileName.initWithFormat("0000%d.png", index);
		char buffer[10] = { 0 };
		std::string temp = fileName.getCString();
		for (int i = 8; i >= 0; i--)
		{
			buffer[i] = temp.back();
			temp.pop_back();
		}
		LabelTTF * info = LabelTTF::create(buffer, "Arial", 13);
		info->setPosition(ccp(128, 128));
		this->addChild(info);
		//	log("load picture %s\n",fileName.getCString());
		request->addFile(buffer, new MapCellResourceCallback(this));
		request->go();
		request->release();
	}
	else request->release();
}