Replies: 1 comment
-
Re-reading my message, perhaps my description was too big, sorry for that. The aim is to set different cells of a Tilemap with the same instance of an instanced scene (when this scene is bigger than 1*1). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm creating a 2D isometric tile-based city builder.
When creating a building, I want to make a "shadow building" follow the mouse on tilemap's coordinates and, on click, have the building created.
The buildings are scene instances imported in the Tileset of the Tilemap. Their sizes are bigger than 1*1 --> 2 * 2, 4 * 3, etc !
When the buidling can't be created (another building already there), the "shadow building" turns to red.
I manage making this work, but I have to call Tilemap's
add_child
myself, setglobal_position
according to mouse position on the map, turn to red when there is an Area2D overlapping.But because of the fact it's a scene instance, the
_ready
function is already called in the step of the "shadow building".That's why I have to create another function to call when the building is effectively created --> let's call it the
create
function.I discovered the method
set_cell
of Tilemap (which would be cleaner).Use it would enable to follow the "right path" and surely simplify the code.
But if I want to use it, I must get the created instance when
set_cell
is called in order to call thecreate
function.This limitation is here because I have to manage the red color on bad positionning (did by script).
Another way would be to only display a Sprite2D as "shadow building".
Via the Tilemap, I could check if the "shadow building" is overlapping another building and create it if not.
The code in the
create
function would then be moved in the_ready
function.That's why I was thinking about these features:
https://user-images.githubusercontent.com/11960112/234028201-35aacec0-ed59-4c0f-80a0-af48e9c26d16.png
set_cell
: length and width.This enable to set the different cells in the area described and link to the scene instance.
The method
get_cell
would then return the same value for the multiple cells under the same scene instance.Beta Was this translation helpful? Give feedback.
All reactions