"Rendertexture"
rendertexture This dynamic texture class , as its name implies, is the ability to dynamically create texture images.
screen main steps:
> start:render->begin ();
> Traversal scenario:scene->visit ();
> End:render->end ();
> Save:render->savetofile (string& filename, Image::format Format);
Where Image::format is a picture format, it can be saved as PNG, or JPG in two different formats.
namely:Image::format::P ng,image::format::jpg.
The first method:
1. Methods
void Helloworld::capture (ref* sender) { Cclog ("screenshot"); Get the screen size size winsize = Ccdirector::shareddirector ()->getwinsize (); Create rendertexture, texture picture size is window size winsize rendertexture* screen = Rendertexture::create (Winsize.width, Winsize.height); Screen screen->begin (); Start scratching the screen this->getparent ()->visit ();//traverse all the child nodes of the scene in the current scenes, and draw them into screens screen->end (); End Capture Screen //Save Screen->savetofile ("Screenshot.png", Image::format::P ng);//Save as PNG format //screen-> SaveToFile ("Screenshot.jpg", image::format::jpg); Save as JPG format}//
2. Save path
> Win32: saved in debug.win32/ directory.
> Android: save in /data/data/com.summer.hello/files/screenshot.png .
=================================================================
The second method;
"Utils::capturescreen"
In the v3.2 version , theUtils::capturescreen () method is added to save the screen.
1. Definition
//> Aftercaptured: This method will be executed after capturing the command. // > BOOL : The capture screen is successful. // > string: The path of the store. //> FileName : the name. // > can be just a file name. screenshot.png like this. // > can also be an absolute path. /sdcard/screenshot.png like this. void Capturescreen (const std::function<void (bool, const std::string&) >& aftercaptured, const std: :string& filename)//
2. Methods
screen void Helloworld::capture (ref* sender) { Cclog ("screenshot"); Utils::capturescreen (Cc_callback_2 (Helloworld::aftercapture, this), "Screenshot.png");} After execution aftercapturevoid Helloworld::aftercapture (bool succeed, const std::string& outputFile) { if (succeed) { cclog ("%s", Outputfile.c_str ()); Display sprite* sp = sprite::create (outputFile); Sp->setposition (WINSIZE/2); This->addchild (SP); Sp->setscale (0.25); Indent } else { cclog ("Capture screen failed.");} } //
3. Save path
FileName can be just a file name (saved to a relative path ): "Screenshot.png"like this.
FileName can also be an absolute path : "/sdcard/screenshot.png"like this.
COCOS2DX 3.x (two ways of the screen)