Games Creation of several characters with the same name using TILED

developer_123

Active Member
Licensed User
Longtime User
Good night. I just created one character (called "spring") with a couple of tiled characteristics. Now I need to create several of those "springs" in my game. At first I thought that with the instruction - TileMap.GetObjectTemplateByName (ObjectLayer, "spring") - TileMap.CreateObject (template) - all the characters with the same name would be created, but I see that it only creates one character. I don't know what the method is to create X amount of characters with the same characteristics. I suppose that with a counter in a FOR and going through all the IDs of the elements created in Tiled, but I see that Tiled generates a random identification number for each created object. I appreciate any clues that allow me to create any number of "springs".
 

ilan

Expert
Licensed User
Longtime User
yes you load it in a loop

you can give each sprind an id and like this you can reference to it in your game and edit it if you like

here is an example:

B4X:
Dim ol As X2ObjectsLayer = TileMap.Layers.Get(ObjectLayer)
    For Each template As X2TileObjectTemplate In ol.ObjectsById.Values
        Select template.Name
            Case "switch"
                Dim bw As X2BodyWrapper = TileMap.CreateObject(template)
                Dim switch As SwitchData
                switch.Initialize
                switch.DoorIds = Regex.Split(",", bw.TemplateCustomProperties.Get("doorid"))
                bw.Tag = switch
            Case "bg"
                'put the "background body" exactly at the center.
                template.BodyDef.Position = X2.ScreenAABB.Center
                TileMap.CreateObject(template)
            Case "ball"
                
            Case Else
                TileMap.CreateObject(template)   
        End Select
    Next
 
Top