RPG Maker MV

RPG Maker MV

Getting x,y coordinates of mouseclick on scrollable map
Hi,
I'm currently trying to figur out how to get the x and y coordinates of a mouse click on a map that is scrollable. (e.g. you can't assume the top left tile has the coordinates 0 0)

The basic idea is clear (get touchInput.x and touchInput.y, divide by 48 and floor it), but this only works if the top left tile visible on the current screen has the 0,0 coordinates.
Any way to do this reliable on a map that is bigger than the default size?
(Please ask questions if further clarification is needed)
< >
Showing 1-2 of 2 comments
Hajami Jul 16, 2016 @ 4:00pm 
I can think of a Workaround.
For example Place an Event001 in the Top Left corner of your huge scrollable map.
Now lets change your math for detection of coordinates.

Var1 = Event001 ScreenX
Var2 = Event001 ScreenY
Var1 - ScreenX of your Mouseclick
for the rest of the math its too late this night....
But that Event allows you to have Screencoordinates to compare with....
Hopes this helps towards correct direction.
Originally posted by Hajami:
I can think of a Workaround.
For example Place an Event001 in the Top Left corner of your huge scrollable map.
Now lets change your math for detection of coordinates.

Var1 = Event001 ScreenX
Var2 = Event001 ScreenY
Var1 - ScreenX of your Mouseclick
for the rest of the math its too late this night....
But that Event allows you to have Screencoordinates to compare with....
Hopes this helps towards correct direction.

Hey,

sorry for the delayed answer, went straight to bed afterwards.
Good thinking! I had a similar thought this morning and it actually works.
For those interested basically do the following:

Place an event on top left corner of the map (Tile = (0,0)). This event needs to take its screen X and Y in two separate variables. If you have the screen position, divide the x value by 48 (and floor it if you want to be safe). Take the abs as it is easier to comprehend for later math.

1) Math.abs(Math.floor($gameVariables.value(YourEventsScreenX)/48))

Of course we need this for Y, too.

After this take your touch/mouse input regularly where ever you need it with

2) TouchInput._x and TouchInput._y

In the last step transform the TouchInput to coordinates as seen in 1) then just add your offset.

3)
// Get touchinput screen coordinates as var x and y and transform them to tilescoordinates
var x = Math.floor($gameVariables.value(1)/48);
var y = Math.floor($gameVariables.value(2)/48);
// add screen offset variables (offsetX = 248 / offsetY = 249)
x = x + $gameVariables.value(248);
y = y + $gameVariables.value(249);
// store it
$gameVariables.setValue(3, x);
$gameVariables.setValue(4, y);

=> Provided Variable 1 = TouchInput._x and Variable 2 = TouchInput._y, as well as Variable 248 = offsetX (the one calculated with the helper event) and Variable 249 = offsetY you get
Variable 3 = ClickedTileX and Variable 4 = ClickedTileY.

Maybe this will help someone in the future, and thanks again for the fast response :)
Last edited by Playstar der G-Sheriff | Fuchs; Jul 17, 2016 @ 1:54am
< >
Showing 1-2 of 2 comments
Per page: 1530 50

Date Posted: Jul 16, 2016 @ 3:45pm
Posts: 2