Dragable map

0 favourites
  • 11 posts
From the Asset Store
A template which allows you to customise the controls of your game.
  • I am making a map that I can zoom in and out like for example google maps. And when I zoom in it centers on where the cursor is.

    How do i make it dragable so that I can hold the mouse button to scroll the map? I have tried the 'scroll to' function but that seems to just move it a bit and not be working as well as I hoped. Any ideas?

    I have sofar got this..

    Cheers for reading!

    Danny

  • Hi,

    Move action "scroll to (mouse position)" on event "every tick"

    or

    on mouse click left -->>> scroll to mouse position

  • That is what i tried but i think the being zoomed in messes it up cause it does move in the right direction but only a fraction of the distance.. This is why i asked here..

  • It would probably be better to create a sprite on left button pushed give it the drag and drop behaviour and pin it to the map so you can drag the map while mouse down.The visual effect would be the same as dragging the viewport over the layout, but ofcourse it could give other issues, depending on the needs of your game.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can use magicam and do that in no time.

    But if you want do it yourself by event then you will need some variables and it should look something like this

    on mouse click:

    Set old_Mouse_AbsoluteX to Mouse.AbsoluteX

    Set old_Mouse_AbsoluteY to Mouse.AbsoluteY

    Set old_scrollX to scrollx*LayoutScale

    Set old_scrollY to scrolly*LayoutScale

    on mouse button is down

    set scroll to:

    X (old_ScrollX+old_Mouse_AbsoluteX-Mouse.AbsoluteX)/LayoutScale

    Y (old_ScrollY+old_Mouse_AbsoluteY-Mouse.AbsoluteY)/LayoutScale

    I'm not on my pc currently but this should work fine.

  • I will try these options and see what works best for me thanks. Really appreciate the suggestions. Cheers!

    Btw.. not making a game whehehe. Just an interactive map for a volunteer group I am in.

    We do repairs and pick litter and such here in town and I am trying to make a map where we can mark things that need attention and mark them DONE when we got to them. Instead of going the usual webdesign route I figured I would try using Construct2 just to see how far I get and it is a good motivator to learn Construct2 a bit better.

    So I will probably have future questions like how do I store data on the server and load it into an array and how to make a secure login that only allows 1 user at a time to be active.. But that is for another time. Probably will be looking at youtubes and such to see if there are answers there first of course. I just love the community feel of the Scirra forum.

    Thanks again!

    Regards,

    Danny

  • I've once made an interactive map with C2 showing in realtime which pubs were open in my hometown..

    I used the Openstreetmap.org maps for it. Dragging etcetera was done through the original leaflet.js.

    I had to adjust a plugin a bit to get it to work, but the effect was pretty nice.

    WatIsOpen

    should work on mobile as well as desktop.

  • great job LittleStain

  • So you mean that map is loaded live from the openstreetmap.org server in its own layer and you made your interactive data in a seperate layer in construct2 as an overlay?

    Am I getting that right? That looks pretty slick I must admit.

    Dank je wel trouwens

  • So you mean that map is loaded live from the openstreetmap.org server in its own layer and you made your interactive data in a seperate layer in construct2 as an overlay?

    Am I getting that right? That looks pretty slick I must admit.

    Dank je wel trouwens

    Yep that's about it..

    The markers on the map itself are part of the plugin, but controllable from within Construct (Appearance/placement)

    They are updated every minute to reflect if the pubs are open or not (using the system time of the device running the "Game")

    Because the map is a DOM-element C2 can't really overlay it (unless you use a div/html-plugin), so I just played with animating the size of the map to uncover the menu's and stuff..

    It took quite some experimenting to get it to work and look right (especially because I wanted it to work on every screensize, mobile, tablet and desktop), but I'm quite happy with the result.

  • I will have to have several members with each their own log in details be able to add and change data (markers with labels) so not sure if this would work for me or how to do it. But from what I understand in the licensing is that I am basically allowed to copy parts of the map. (at least until the town council here provides me with one) That way I can put it in Construct2 and have people log in to the 'game' to change stuff there. Not sure what a DOM element is btw.

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