cocos2dx 从节点中获取图片对象

Image* HelloWorld::getImageFromSprite(Sprite *sprite)
{
	Vec2 oldPos = sprite->getPosition();
	Vec2 oldAnc = sprite->getAnchorPoint();
	sprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
	sprite->setPosition(sprite->getParent()->convertToNodeSpace(Vec2::ZERO));
	Size size = sprite->getBoundingBox().size;
	RenderTexture *render = RenderTexture::create(size.width, size.height);
	render->beginWithClear(0, 0, 0, 0);
	sprite->visit();
	render->end();
	Director::getInstance()->getRenderer()->render();
	sprite->setPosition(oldPos);
	sprite->setAnchorPoint(oldAnc);
	return render->newImage();
}

你可能感兴趣的:(c++)