Canvas snapshot in scripting?

0 favourites
  • 5 posts
From the Asset Store
Here is the wonderful & amazing script for your website or fun with maths.
  • Is there a non-silly way to get a canvas snapshot in script? Am I overlooking something? Specifically I wanna load it into a sprite, and currently I have to do a whole bunch of ??? to get the blob. I cannot access the snapshot directly in script but I also cannot hand it off via a variable because these don't support blob urls.

    await runtime.callFunction("snapshot");
    let response = await fetch(this.snap);
    this.snap = await response.blob();
    const img = runtime.objects.transitionSprite.getFirstInstance();
    await img.replaceCurrentAnimationFrame(this.snap);
    

    I've also tried to use new URL(this.snap) in hope to get an URL which does seem to work but it then fails at img.replaceCurrentAnimationFrame() due to wrong type. Further I've tried to directly access the context of the c3canvas but that also wasn't exactly working, I didn't spend too much time on it since I expect this to be hacky anyway.

    On a sidenote, since we're talking canvas snapshot: Is there a good way to snapshot only some layers? I know I can briefly hide the stuff I don't wanna snapshot (e.g. UI) but since snapshot is async it will cause the UI to flicker which isn't exactly neat. Not sure if there's any workaround for that.

  • If there isn't an API covering it in the documentation, then it's not supported and you'd need to post a feature request. However your workaround looks reasonable - get the URL from the event sheet and fetch that as a blob. I've definitely seen worse workarounds!

  • Alright thx, feature request it is. The workaround is ok, but I always set out to do a game and make it "javascript only" just to end up back in the event sheet for random reasons. Either be it workarounds, missing APIs (or intentionally left out) or simply convenience with some things. Not a bad thing per se but not exactly what I plan, haha.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Alright thx, feature request it is. The workaround is ok, but I always set out to do a game and make it "javascript only" just to end up back in the event sheet for random reasons. Either be it workarounds, missing APIs (or intentionally left out) or simply convenience with some things. Not a bad thing per se but not exactly what I plan, haha.

    I feel you, however after awhile you will notice that some stuff is just easier to do in the event sheet, code is still js even if you use the event sheet, i usually say if someone has done it, why redo it 😉 that said i had the same issue with some stuff like pin etc, where i had to create it myself, but then i said screw it and just used the event sheet, works fine for simple things like on start of layout etc.

  • Well the Pin behavior is at least (sort of) deprecated in favor of hierarchies. so I understand there not being an API.

    Things that I have in my events are currently:

    "Draw on tilemap with brush" since this is not available in js out of the box. I know it's possible to do bitwise operations blablabla but as you said: why bother, it already exists, just make a lil function to call.

    "Recreate initial objects" which is also not available in scripting. I specifically need it to load template layouts, which was added a while back. I don't even think there is a way to do this in js at all. I can get the ILayout but that doesn't help since there's no access to the initial instances. So I'd somehow have to do some weird workaround like go to the layout, store the instances, go back, then create them... or just do a lil function call.

    It's really not that big of a deal in most cases, but that said, I'd still prefer just having these options available in scripting directly. Now that I think about it, I should probably also just add feature requests for these too but I don't wanna spam so many feature requests either :V

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)