Games Inconvenience with deleting Tiled bodies

developer_123

Active Member
Licensed User
Longtime User
This is a follow up request for : https://www.b4x.com/android/forum/t...is-for-objects-from-tiled.140262/#post-888593

Erel, I hadn't been able to answer the last question you asked me in the related post, since due to a matter of time I couldn't advance as long as I wanted with all the pending issues in my app.

Answering the questions, I am trying to delete the bodies with bw.Delete(bw.X2.gs) but it doesn't happen, I even set a body time to live with bw.TimeToLiveMs=1 , but it doesn't.

I am getting the bodies of the Sub World_BeginContact, bodies.OtherBody.

In the example you provided I see that from Tiled the life time is configured and for this reason I suppose that it does not cause a problem, but I think that with a command from B4X it should respond in the same way.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've updated the example from the other thread.
Clicking on a body deletes it.

The relevant code:
B4X:
Private Sub HandleTouch (gs As X2GameStep)
    Dim touch As X2Touch = Multitouch.GetSingleTouch(PanelForTouch)
    If touch.IsInitialized Then
        Dim worldpoint As B2Vec2 = X2.ScreenPointToWorld(touch.X, touch.Y)
        Dim bodies As List = X2.GetBodiesIntersectingWithWorldPoint(worldpoint)
        If bodies.Size > 0 Then
            Dim bw As X2BodyWrapper = bodies.Get(0)
            bw.Delete (gs)
        End If
    End If
End Sub
Tested with B4J.
 

Attachments

  • Project.zip
    42.8 KB · Views: 210

developer_123

Active Member
Licensed User
Longtime User
I've updated the example from the other thread.
Clicking on a body deletes it.

The relevant code:
B4X:
Private Sub HandleTouch (gs As X2GameStep)
    Dim touch As X2Touch = Multitouch.GetSingleTouch(PanelForTouch)
    If touch.IsInitialized Then
        Dim worldpoint As B2Vec2 = X2.ScreenPointToWorld(touch.X, touch.Y)
        Dim bodies As List = X2.GetBodiesIntersectingWithWorldPoint(worldpoint)
        If bodies.Size > 0 Then
            Dim bw As X2BodyWrapper = bodies.Get(0)
            bw.Delete (gs)
        End If
    End If
End Sub
Tested with B4J.
Which are the difference between obtaining the bodies from the BeginContact and obtaining it from the intersection list with the touch event? Why can I delete the body in one way and not the other? It turns out that I already have the code and several functions that execute various events with the body obtained from the begincontact, and I would not want to modify the condition to a touch match, since this would imply in my case adjusting quite a few lines. I would assume that the delet function should work in any case that it is called. Is there something I can do to remove the body, obtained from the BeginContact?
 
Top