How to center map? (Solved)

Hello,
i am trying to show a map not from the start of the game but later.

I have set the Map-Grid to 0 with

JS.ShowGrid (0)

and in the Moment i want show the map i use

JS.ShowGrid (300)

Works well so far, but the playerposition-y-coordinate seems to be 0 at the first mapdrawing. It would be very nice, if i could show the map with the player not at the top-screen-border, but in the middle of the map area.

So i could use a command to change the player-coordinates or a command to center the map.

Anyone has an idea?


Found it

Grid_SetCentre (int x, int y)

center on the player:
Grid_SetCentre (0,0)

Thanks :)


Not sure on this one, but I think you might be looking for:

Grid_SetCentre(x, y)

Not sure if this is relative to the player, or if you need to pass it the player's coordinates. If you need coords, there doesn't seem to be an easy way to find them, so it would probably end up being something like:

room = game.pov.parent
player_x = Grid_GetGridCoordinateForPlayer(game.pov, room, "x") + room.grid_width/2.0
player_y = Grid_GetGridCoordinateForPlayer(game.pov, room, "y") + room.grid_height/2.0
Grid_SetCentre(player_x, player_y)

(I haven't checked this; it's possible SetCentre uses some weird coordinate system like pixels on the map rather than the system used for room coordinates, or something like that… but figure it might be worth trying)

Alternatively, you might need to do something like:

      JS.ShowGrid (300)
      Grid_SetScale (300)
      Grid_Redraw
      Grid_DrawPlayerInRoom (game.pov.parent)

That's what the core library does at the start of the game if the grid is enabled. I'm not sure how much of that is necessary when changing the size of the grid later, but as they always appear together in the core code, it's possible that ShowGrid expects Grid_SetScale to be called after it to sort out centreing; or that SetScale expects to be followed by a GridRedraw.

I'd probably try different combinations of the lines to see which ones behave as expected.


Thx a lot MrAngel,

The Solution with Grid_SetCentre (int x, int y) works well, and it really uses a weird system. My first try with
Grid_SetCentre (100,100) shows me nothing on the map - so i think it uses the standard-room-sizes as unit, or something like that.

I tried Grid_Redraw, too, but was so stupid and tried it at the wrong location (wrong verb) - so i dont know if this would work, too.

Thanks again for the solutions... works all fine now... !


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums