Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Can you take screenshots with Codea-API in FULLSCREEN_NO_BUTTONS?

edited September 2020 in Questions Posts: 142

I have a question regarding taking screenshots using the camera icon in the bottom-left corner. When using it, I was able to save the image and set it as the icon of the project. However, touching the button to tweet the screenshot closed the window and nothing else seemed to happen. Is this behaviour intentional and I'm just missing something or is this a bug?

Also, is it possible to provide this feature in an exported app (without the option of setting the screenshot as an icon)? I'd like to call the function for taking a screenshot manually by putting a button in my game. Having the option to use twitter would be great since players could share pictures of what they have accomplished. I couldn't find anything about this in the documentation. It seems as if you can't call the API for taking a screenshot and opening the menu for sharing and saving manually.


  • edited September 2020 Posts: 142

    Any ideas? I haven't been able to get this to work :#

  • Posts: 1,965
    @Leon - I think it should be possible if you program a touch to initiate screen capture. But, don't forget iOS permits you to take a full screen image capture by pressing the home and power buttons at the same time briefly. So you can capture apps in use.

    This presents a small image in the bottom left hand corner to tap and then edit/save.
  • Posts: 142

    @Bri_G Thanks! When you press the camera-icon in the bottom left corner, Codea takes a picture and then opens a small menu that allows you to share the image to Twitter. That's the main thing I'd like to integrate into my game. However, I couldn't find any documentation on how to trigger that in FULLSCREEN_NO_BUTTONS, when the camera icon in the bottom left is hidden.

  • Posts: 1,965
    @Leon - you should be able to use parameter.action() to make a call for saveImage() to copy the screen. You could set it up for a multiple tap in the touched() function and switch to display mode(FULL SCREEN) before capturing the screen. Note I think it will record two images normal res and retina res.
  • edited September 2020 Posts: 142

    @Bri_G Thanks again! The problem is that this doesn't sound like a practical solution since I'd like to publish my game on the AppStore. Also, my issue isn't taking a screenshot, but that I'd like to trigger the exact action touching that the camera icon has. Meaning that after taking a screenshot, the menu that allows you to twitter the screenshot opens up. Is there a function that replicated the exact action of the camera icon?

    Edit: Maybe this can be done using openURL. I'll give it a try

  • Posts: 1,965

    @Leon - take a snapshot of your screen now (using the iOS method. Tap the small icon of it in the bottom right corner and open the editing page. Look at the top right corner of the screen and you can see the sharing icon - tap on that to see what sharing options you have.

  • Posts: 142

    @Bri_G Yes, but that's too inconvenient for most players. They are used to clicking one button and being presented with a pre-made tweet that includes a hashtag as well as the image. Otherwise, they probably won't bother.
    Also, that's exactly what the camera button in Codea does. When using the tweet option, the twitter app is opened and you are presented with a pre-made tweet that includes the screenshot and a hashtag.

  • JohnJohn Admin Mod
    Posts: 643

    @Leon this is probably something that could be added to Codea's API since we already have for controlling screen capture via code

  • Posts: 142

    @John That would be awesome! The only problem could be, that the menu that opens after taking a screenshot allows you to use the image as the project icon.

  • edited November 2020 Posts: 142

    With the new snapshot-API, it is now possible to take screenshots. However, I still struggle with the sharing part. Is it possible to recreate the functionality that Codea has? When using the camera icon in the bottom-left corner, a screenshot is taken and a menu pops up that allows you to share the image via twitter. When pressing that button, twitter is opened with a pre-made post that already includes the screenshot. I was't able to recreate this. According to the forum, it is possible to open twitter with a post that includes prewritten text using openUrl(). Is this somehow possible for pictures as well or how does Codea handle this?

  • SimeonSimeon Admin Mod
    Posts: 5,449

    @Elias I've added a new share function to Codea 3.2.9 (beta). You can use this to present the system share picker (not Codea's though) so the user can share an image or text to another service like Twitter

  • Posts: 142

    @Simeon Amazing, thanks! This is exactly what I needed :)
    I encountered some minor issues:

    1) Some elements weren't captured with viewer.snapshot(). After some trial and error I believe this is because of 'translate()'. I use translate for a 2d-camera that follows the player. When drawing UI-elements, I reverse this by using translate again. Some of those elements that are drawn afterwards are not part of snapshot.
    2) It would be nice to check, whether the sharing dialogue is already opened. Is this possible?
    3) When saving an image to the library, Codea quits running the project and returns to the code editor

    I hope it doesn't come across as unfriendly to list those issues. I'm very happy with the current implementation :)

  • SimeonSimeon Admin Mod
    Posts: 5,449

    Thanks for the great feedback @Elias. I'll continue to update the share function during the beta

    Do you have a simple test case where viewer.snapshot() fails?

    Also, I might move alert and share into the viewer namespace

  • Posts: 142

    @Simeon Great, thanks!
    While I was trying to put together such a test case, I realized that (1) was caused by a stupid mistake I made. By accident, I put the code to take the snapshot before some sprites were drawn. Obviously, those sprites were missing from the screenshots.
    I was able to reproduce (3) in every test. When saving a snapshot to the library, Codea quits running the current project.

  • SimeonSimeon Admin Mod
    Posts: 5,449

    3) looks like an iOS 14 bug. I've added a workaround to the next build

  • edited December 2020 Posts: 142

    Seems to be working great. I've tried saving it quite a few times and didn't run into any issues :)

    After playing around with share a little more, I had to think about this:
    It would be pretty cool to use createProject outside Codea and then use share to re-import a project. In theory, this could enable some utility apps for Codea. However, this only makes sense if the implementation is straightforward as only very very few people would ever use it.

Sign In or Register to comment.