Screenshot in-game for mobile?

Well, not without building manually to add a Cordova plugin and some Javascript at least.

Well, then there is a solution, right?
How i start to do what you said?

There is a way to create an extension for take screenshoot, give me few hours and will coding that it’s simple :slight_smile:
But for saving files on mobile it’s more complicated i don’t know how it’s working.

But i can already create the screenshot. :slight_smile:

1 Like

I wrote a very complete post some time ago let me find it will take a minute

1 Like

Here it is: [Solved]Saving values of variables to file - #2 by arthuro555

1 Like

Wow, if you really can do it, it will be really cool! I will be really grateful! @Bouh @arthuro555

Wait I found another solution. Create a Js event with this content:

navigator.screenshot.save(function(error,res){
  if(error){
    alert("there was an error while saving the screenshot. Error code: "+error);
  }
});

Then export manually. You will need to install Cordova, to do so first install NodeJS then open a command prompt, change the directory to the one where you exported for mobile/cordova, then type

npm install --dev cordova
// and to install the screenshot plugin
cordova plugin add https://github.com/gitawego/cordova-screenshot.git

But there is alredy an action for take and save a screenshot !
I know it !

You have also an example in GD5 !

So no need extension for take a screenshot ^^
If you search the action type in search bar “Take” you should see this
image


if someone is interesting by screenshot with javascript :

//For see entire base64 string in developper tool
//console.dir(screenshot)


//Get canvas of game
const renderer = runtimeScene.getRenderer();
const canvas = renderer._pixiRenderer.view;
let screenshot = canvas.toDataURL("png");

//open image in new tab
window.location = screenshot;

//Open image in new tab but for download the file.
window.open(b64toFile(b64, "filename", "png"));

//From stackoverflow
window.b64toFile = function (b64Data, filename, contentType) {
    var sliceSize = 512;
    var byteCharacters = atob(b64Data);
    var byteArrays = [];

    for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
        var slice = byteCharacters.slice(offset, offset + sliceSize);
        var byteNumbers = new Array(slice.length);

        for (var i = 0; i < slice.length; i++) {
            byteNumbers[i] = slice.charCodeAt(i);
        }
        var byteArray = new Uint8Array(byteNumbers);
        byteArrays.push(byteArray);
    }
    var file = new File(byteArrays, filename, {type: contentType});
    return file;
}
1 Like

But does it work for mobile too? I thought it only worked for the computer

I don’t know about cordova i’ve never really used this.
@arthuro555 have you already test to save the file with your code ?

There is no solution?

I am not sure we have to test. I am not on PC right now so I cannot. I will keep you updated.

Okay, thanks! I’ll wait for good news haha

I actually totally forgot! I will try later but right now it’s 1am and I’m going to sleep now.

so did you get the good news? mobile in game screenshots?

I’m interested too…

There is a sample project in the engine for screenshot, the only problem is the screenshot path is set to desktop, but if you should set the path for mobile either to sdcard or internal i am sure it should work.

For Pc:

FileSystem::DesktopPath() + FileSystem::PathDelimiter() + “GDevelop_Screenshot.png”

For mobile:

FileSystem::SDcardPath() or InternalstoragePath + FileSystem::PathDelimiter() + “GDevelop_Screenshot.png”

Hii! :smile:

Have you tested? I tried it a little while ago, but without results, maybe i did it wrong… But i don’t know if it really works, could you tell me if you already tested it?

Please read the question throughly before answering. The Filesystem is only accessible on PC not on mobile, so this wouldn’t work.

any update??? need this too…