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

Get help using Construct 2

Post » Tue Dec 27, 2016 10:44 pm

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: viewtopic.php?f=147&t=121671&p=868697&hilit=capture+area+canvas#p868697

I followed your instructions exactly but I am still having this issue.
B
74
S
14
G
4
Posts: 1,015
Reputation: 8,133

Post » Wed Dec 28, 2016 6:35 am

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.
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

Post » Wed Dec 28, 2016 11:03 am

R0J0hound wrote: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:

R0J0hound wrote:@AllenR
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:

Image

Just to illustrate:

Image

Obs: The "screen" sprite is the grey rectangle and the canvas plugin is filling all the white area.
Last edited by RBuster on Wed Dec 28, 2016 4:04 pm, edited 1 time in total.
B
74
S
14
G
4
Posts: 1,015
Reputation: 8,133

Post » Wed Dec 28, 2016 1:36 pm

Posting an example .capx would save a lot of guesswork and possible confusion.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
137
S
31
G
87
Posts: 5,548
Reputation: 60,440

Post » Wed Dec 28, 2016 11:15 pm

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.
B
74
S
14
G
4
Posts: 1,015
Reputation: 8,133

Post » Thu Dec 29, 2016 12:25 am

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.
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

Post » Thu Dec 29, 2016 11:32 am

R0J0hound wrote: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.
B
74
S
14
G
4
Posts: 1,015
Reputation: 8,133

Post » Thu Dec 29, 2016 6:11 pm

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.
B
94
S
33
G
118
Posts: 5,392
Reputation: 75,845

Post » Thu Dec 29, 2016 6:32 pm

R0J0hound wrote: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.
B
74
S
14
G
4
Posts: 1,015
Reputation: 8,133


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 8 guests