How do I get a snapshot from the specific canvas area?

0 favourites
  • 9 posts
From the Asset Store
Pixel Destruction like in "Worms" (Drawing Canvas based)
  • I am using canvas plugin and I need o get a snapshot from the specific area of the canvas. The canvas plugin is filling the entire screen (1280,720) but I just want an area in the middle of the screen, where is the sprite.

    I am using:

    Set canvas size (screen.width/screen.height)

    Set scroll to (screen.x/screen.y)

    And after take a snapshot I restore de original sizes and positions.

    The issue: I am not getting the area I want. The image seems offset. I have tried to use the values instead the sprite (screen) location/size but it is not working too.

    R0J0hound

    I saw your answer in this topic:

    I followed your instructions exactly but I am still having this issue.

  • Here's a better approach I found after the link above.

    You set the viewport size to the size you want.

    Next scroll to the center of what you want to capture.

    Then use the snapshot canvas action.

    When it's done you can then set the viewport back to normal and scroll back so it's centered.

  • Here's a better approach I found after the link above.

    You set the viewport size to the size you want.

    Next scroll to the center of what you want to capture.

    Then use the snapshot canvas action.

    When it's done you can then set the viewport back to normal and scroll back so it's centered.

    Thanks for the reply.

    Sorry but I did not understand the difference between what I did and what you suggested.

    You have suggested the following in that post:

    You can use the Snapshot action instead. For for a 100x100 image centered on position 50x50 you could do this:

    ---Set canvas size to 100x100

    ---scroll to (50, 50)

    ---Take Snapshot

    on snapshot

    ---set canvas size to 640x480

    ---scroll to (320,240)

    ---invoke download of canvasScreenshot

    The second scroll to is to scroll back to the original scroll location. If the layout isn't using unbounded scrolling you could also use (0,0).

    Is it not the same?

    My code:

    Just to illustrate:

    Obs: The "screen" sprite is the grey rectangle and the canvas plugin is filling all the white area.

  • Posting an example .capx would save a lot of guesswork and possible confusion.

  • I have included the script I am using in my previous post. It's the only code referring to this problem.

    I really need to get this feature working and I will appreciate any possible help.

  • I haven't tried it in a bit but you may also need to wait a tick after setting the canvas size for scroll to to work.

  • I haven't tried it in a bit but you may also need to wait a tick after setting the canvas size for scroll to to work.

    Thanks. It worked.

    Taking the opportunity, I wonder it is possible to check if the user drew something in the canvas (plugin)? I would like to allow them to proceed to the next screen after this.

  • You could either a)check all the pixels with a loop, or b)set a variable when one of the actions to draw to the canvas is used. The latter is faster.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could either a)check all the pixels with a loop, or b)set a variable when one of the actions to draw to the canvas is used. The latter is faster.

    Thank you. You really helped me a lot.

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