0 votes

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

in Engine by (42 points)

Screenshot didn't come out...

1 Answer

0 votes
Best answer

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

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

Regards.
-j

by (1,469 points)
selected by

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

I also found this: https://github.com/godotengine/godot/commit/ecb4d41d20cf9a29f4acf5f00b9efd2659280f2a
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.

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.