Now what I want to do is to create another object within this green map area ONLY (like in the screenshot below). Nothing outside of it. I am not able to find a way to get any function or any other logic to be able to determine this area or zone or co-ordinates within which the objects can be created.
Also, point to note is that in the future I could have many different maps and would need a scalable logic to be able to place objects in the map irrespective of the type of map.
mmm…have u tried with the tiled built in add layer?
As far as i know you can’t import in GD multilayered tiled maps.
But you can create new layers in Tiled (that overlaps) then import each one as single Tiled objects…
i mean …you can try to multilayer in Tiled as long it is 1 json file and 1 tileset image
I already had created the map in Tiled with 2 layers as you can see below.
In G develop, we do have the functionality to select the layer which we want to display by selecting its index in the properties. Check below screenshots:
I was just pondering over this last night while going to sleep , and I think I found 1 way to do it by using a loop which generates a random X and Y coordinate and then checks if it’s colliding with the collision mask of this map. If yes, then it should be mostly inside the map, however, I am not sure again how to deal with the edge case where a point could be on the border/edge of the collision mask - in that case I would have the case I mentioned in point 4 in my original post, so need help for that case
I understand what u want but i don’t think it can be done since tiled objects are recognized as single squared object (if you check the collision debug action you should see it).
as far as i know there is no way to identify a coordinate inside the tiled object (or on the edge) exept the bounding box, origin and center.
U could try something whit the bounding box conditions…but I don’t think it would work in your case.
and imo continuously cheking if the collision happen may works at beginning but it would impact on performances a lot later…
Yes true, I have struggled with external tilemaps in G develop for the reasons you mentoined, and there are no functions to check specific co-ordinates inside tiled object. Maybe I will try using the in-built tilemap editor in G develop as that provides some more functions such as checking the exact tile ID etc.
I just created the following event sequence right now, and it seems to work except for the edge part like I mentioned earlier:
Pick random X and Y coordinates from the range in which the map would be on the screen (keeping some buffer from the edges of the screen)
Test collision of the object at that co-ordinate with the collision mask of the map
If it collides then set a flag and exit the loop and change the position of the object to that co-ordinate
You mentioned performance issue with this piece of logic - but would it really be there, if :
This loop is only intended to run at the beginning of the game - once the objects are placed, it wont be needed
At a maximum 5 to 6 such objects would need to be placed inside the map
I also suppose, that the probability of this loop running multiple times should be less (but maybe it might run a bit more, once suppose 4/5 objects are placed and for the 5th one, the remaining available space in the map would be less - would need to also check collission with other such objects which are placed around before it)