Screenshot in-game for mobile?


#1

Hiiiii!
Recently, my game (baby idol) made with Gdevelop is gaining high visibility. It’s a character dressing game and the people are starting to ask for the screenshot within the app, there is a way to do this in-game screenshot function for mobile?
If there is any way to do this please let me know. :two_hearts:


#2

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


#3

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


#4

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:


#5

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


#6

Here it is: [Solved]Saving values of variables to file


#7

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


#8

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

#9

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;
}

#10

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


#11

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


#12

There is no solution?


#13

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


#14

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


#16

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


#17

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