How to get size of tilemap

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By apb1963
:warning: Old Version Published before Godot 3 was released.

I created a tile map with images of a brick wall 50px square. I painted a rectangle using this map. I want to get the dimensions of said rectangle so I can restrict the movement of my sprite to either inside or outside the rectangle/room.

Currently I’m doing this: if (cur_pos.x < 740 ), but I don’t want to hard code numeric literals.

I tried creating a wall object that was just barely the size of the inner rectangle but it has no texture so I can’t get its size and a tilemap isn’t a node so I can’t get its size either.

I don’t know how to go from tilemap to texture. Or whatever the correct way of doing this might be. Thank you in advance!

  • APB

P.S. As I finished typing this it occurred to me that I could simply add a random texture to the wall object, but I’m not sure that’s going to help any.

Screenshot

Screenshot didn't come out...

apb1963 | 2017-03-21 01:50

OK, lets try this a different way… here’s the link, a few slightly different ways just in case…

http://picpaste.com/wall_size_2017-03-20_18-21-58-E3KwqsEt.png
http://picpaste.com/wall_size_2017-03-20_18-21-58-E3KwqsEt.png
http://picpaste.com/wall_size_2017-03-20_18-21-58-E3KwqsEt.png

apb1963 | 2017-03-21 01:53

:bust_in_silhouette: Reply From: jospic

Hi,
a little while ago I had asked a simil question:

https://forum.godotengine.org/3276/tilemap-size

Regards.
-j

Thanks! That post enabled me to find this much more complete answer: https://forum.godotengine.org/7450/how-do-i-get-tilemaps-size-height-and-width-with-script

I also found this: Add Rect2 TileMap::get_used_rect(), closes #4390 · godotengine/godot@ecb4d41 · GitHub
which seems to imply it’s a method to do the same thing differently but as an internal method however I’m not clear that it actually does in fact do the same thing. It gets the “used rectangle”. I don’t understand how to use it at this point so I’ll likely go with the above link, but I wanted to point it out in case it helps someone else; or maybe someone can explain or better provide an example of how to use it.

apb1963 | 2017-03-21 20:31

2.1.3 has a get_used_rect for TileMap, not sure if will help.

eons | 2017-04-11 22:46