Dragable map

Get help using Construct 2

Post » Mon Apr 13, 2015 2:52 pm

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

Image

Cheers for reading!
Danny
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Mon Apr 13, 2015 3:29 pm

Hi,

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

or

on mouse click left -->>> scroll to mouse position
Image Image
B
22
S
13
G
130
Posts: 869
Reputation: 67,816

Post » Mon Apr 13, 2015 3:57 pm

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..
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Mon Apr 13, 2015 4:24 pm

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.
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 » Mon Apr 13, 2015 4:40 pm

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.
ImageImageImageImage
B
157
S
64
G
41
Posts: 2,590
Reputation: 34,640

Post » Mon Apr 13, 2015 9:26 pm

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
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Mon Apr 13, 2015 10:55 pm

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.
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 » Mon Apr 13, 2015 11:05 pm

great job @LittleStain
Image Image
B
22
S
13
G
130
Posts: 869
Reputation: 67,816

Post » Mon Apr 13, 2015 11:15 pm

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 ;)
B
54
S
7
G
8
Posts: 150
Reputation: 5,817

Post » Tue Apr 14, 2015 12:23 am

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

Next

Return to How do I....?

Who is online

Users browsing this forum: el3um4s, Ryan Kocourek, TheSupreme, TylerJS and 12 guests