[SOLVED] CanvasToLayer without displacement?

Get help using Construct 2

Post » Fri May 22, 2015 5:19 am

Having a project with a map on which i place little flags (markers) and I drag and zoom the layers that have the map on it. The rest of the layers with for example the UI stays at scale 1. This caused a problem where if the layers with the map and markers were zoomed in and I placed a new marker the coordinates needed adjusting, so I used CanvasToLayerX(2, mouse.X, mouse.Y) and CanvasToLayerY(2, mouse.X, mouse.Y). Everything went fine and the flag would show up where I clicked on the map. Then I pin the flag to the map so when I scroll (drag) the map they move along with it.

Now when placing a marker I send the coordinates I got from CanvasToLayerX and CanvasToLayerY to a mysql database. On start of layout I load them.
They do not load in the right spot though.

When I place the markers while all layers are at scale 1 (completely zoomed out) and I load them while the map is at scale 1 it all works. If I place the markers while zoomed in though, they fail to load on the correct spot.

I hope this is clear without uploading a .capx cause I would have to edit a lot on my project to not give away server details and such.
Last edited by UberDark on Sat May 23, 2015 11:04 am, edited 1 time in total.
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Fri May 22, 2015 11:45 pm

Anybody got a clue?
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Sat May 23, 2015 8:11 am

When you say you send the coordinates of canvastolayerX to a database, how do you do this?
Wouldn't it be better to send the coordinates of the just created marker?

on marker created - send marker.x, marker.y
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat May 23, 2015 8:21 am

But that would send the coordinates of where it appears on the screen at that time. Not where it would be when the map is zoomed out.
So i tried to quickly zoom out to scale 1 and then send it but that still seems to leave it buggered.
Tried so many things on this..

I can show you the capx but it is quite a cluttered project. And i also don't really want to send it to everyone..
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Sat May 23, 2015 8:27 am

So is the marker created on another layer than the map?
For when created on the map layer wouldn't the coordinates be in sync with the map at all times?

If not you might want to try zooming the map to scale1 sending the coordinates and zooming the map back to the scale it was within one event..
If it's all done in the same tick, it would work like the checking for overlap at offset, and not be visible for the user..

Haha.. You already tried that..
Misread..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat May 23, 2015 8:36 am

The map and markers are at different layers but they zoom (scale) the same.
When you send coordinates without CanvasToLayer, those are relative to the viewport though (the canvas object).

And yes i tried the zooming quickly trick.
I also tried putting an object on the top (not scaled) layer exactly over the place where i put the marker and using that coordinates. Again no luck. Not sure why those last two options did not work though for it seems to be flawless logic.
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Sat May 23, 2015 8:54 am

Problem here is this:

Although the zoom is the same, the paralax doesn't seem to be..
You pin your marker, so it moves with the map, but the coordinates of the marker and the map don't appear to be the same..

What you might be able to do, depending on how you've got things set up, is get the position of the marker relative to the position of the map, so the offset-coordinates..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat May 23, 2015 9:09 am

I guess you could also set the map sprite back to it's original position after pinning the marker and then use the marker's x and y..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat May 23, 2015 9:11 am

Paralax of both layers is set to 100, 100.
Or are you saying there is a paralax difference always regardless of the settings?

And when the map is fully zoomed out it automatically centers btw..
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Sat May 23, 2015 10:36 am

So LittleStain pointed out to me in PM that my problem is i am moving the map but not the layer when i use drag and drop. This cause the coordinates to mess up. Solution would be to store the markers position in relation to the map (offset) and when they are loaded offset them to the same spot.

Very insightfull and helpfull thank you.
Going to give that a go now :D
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Next

Return to How do I....?

Who is online

Users browsing this forum: davidbox, Mayfly, Yahoo [Bot] and 4 guests