how to save screenshot on camera roll for iOS and ANDROID using COCOS2DX V3.10 and Javascript

  • Xabaras78
    Likes 0

    Problem Description

    Hi guys,

    i’m using Cocos2d-x JS version and CocosHelper. I’m successfully taking screenshots of my game with this code

    cc.director.setNextDeltaTimeZero(true);
    var renderTexture = new cc.RenderTexture(cc.winSize.width, cc.winSize.height);
    renderTexture.begin();
    cc.director.getRunningScene().visit();
    renderTexture.end();
    fileName = "Screenshot.png";
    imagePath = jsb.fileUtils.getWritablePath();
    var result = renderTexture.saveToFile(fileName, cc.IMAGE_FORMAT_PNG);

    and this correctly creates the image in the app folder, so that i can share it on facebook and twitter, using cocoshelper (even if image share on fb doesn’t work with Android...)

    Now, i’d like to save that screenshot on the camera roll too… but i don’t know where to start… or if it’s possible with Javascript… Any advice?

    Many thanks

    Alessandro

  • Sonar Systems admin
    Likes 0


    This reply has been verified.
  • Xabaras78
    Likes 0

    And it works perfectly… i had never called Objective-c methods from js before… Very useful and powerful!

    many thanks!

  • Sonar Systems admin
    Likes 0

    Great to hear it helped.

     

    Feel free to post anymore questions you may have.

Login to reply