[SOLVED] CanvasToLayer without displacement?

0 favourites
  • 11 posts
From the Asset Store
In this template the music plays without looping in your game
  • 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.

  • Anybody got a clue?

  • 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

  • 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..

  • 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..

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 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..

  • 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..

  • 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

  • Works like a charm!

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