COCOS2DX 3.x (two ways to screen capture)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.