Games X2 some Question

ilan

Expert
Licensed User
Longtime User
hi

Every time i started a project using X2 i ended up quieting and switching to another framework but now i started a new project and i am not giving up until i have a finished product.
the thing is that X2 fills like it is missing some stuff and some are unclear so i will use this thread to put some question and this could be helpful for other developers.

i will start with few question but i am sure the list will grow 😁

1, if i want to delete a body from the scene i tried to use bw.delete(x2.gs) but it seems like it is deleting the bodywrapper object with its graphics but not the physic body itself so i use a different way the same as in other frameworks

B4X:
world.DestroyBody(bw.Body)

if i check the x2 source i see that the Delete function adds the body to the GameStep BodiesToDelete List but it is not deleted. maybe i am doing something wrong

B4X:
Public Sub Delete (GS As X2GameStep)
    If IsDeleted Then Return
    #if Not (X2SkipLogs)
    Log($"Deleting body: ${Name}, ${Id}"$)
    #end if
    IsDeleted = True
    GS.BodiesToDelete.Add(Body)
    If mGraphicName.StartsWith(X2.GraphicCache.TempPrefix) Then
        X2.GraphicCache.RemoveGraphics(mGraphicName)
    End If
End Sub

2, in other framework i have Category BitMask, Collision BitMask and Test BitMask. In X2 i have only Category and Collision Bitmask so Test BitMask is missing.
So why do we need Test Bitmask? The reason is this. Category Bitmask assign a body to a specific Category now we can control wich bodies will collide with the collision Bitmask.
BUT if i want Category 1 to collide with Category 2 but not Collide with Category 3 BUT still get a report of collision i cannot do it without having Test Bit mask. So basically Test Bitmask allow you to still have Collision Report with 2 bodies that will not physically collide with each other. You would say now set the Body to isSensor = true and you have the same effect. Well, wrong because if you set the body to isSensor it will never physicaly collide with any other Body.

3, i am missing a TouchEvent for each body. So Spritekit you can add for each body a touch event. This is really helpful for making Menus using Tiled. In libGDX you have an event that trigger all touches but in X2 you do that in the main Tick(GS as X2GameStep) Event. Now after adding some features you can imagine how long this event can get. It would look much nicer if there would be a specific event only for the Touches.

4, if i create a chainbody in Tiled (so a polygone that is nto closed) it will create it in X2 but i cannot rotate. is this a bug or is this normal?

more question will follow :)

thanx
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Search for BodiesToDelete in the source code. You will see that there is a sub named RemoveDeletedBodies that removes the bodies after the tick event. You cannot delete bodies inside the tick event.

2. I'm pretty sure that there is no collision bitmask in Box2d.

4. Not sure. Try to create a small project and I'll check it. It might be a requirement to have closed polygons.
 

ilan

Expert
Licensed User
Longtime User
thank you erel for your reply

1. Search for BodiesToDelete in the source code. You will see that there is a sub named RemoveDeletedBodies that removes the bodies after the tick event. You cannot delete bodies inside the tick event.
Actually i am not deleting the body in the tick event. i am doing it by calling a Sub from a button click. I thought that if i call bw.delete from anywhere in the code it will do the job. So how is the correct way to delete a bodywrapper object including its bodies/joint etc?

2. I'm pretty sure that there is no collision bitmask in Box2d.
maybe you are right. i took it from SpriteKit and LibGDX. Never mind i will find a solution for that

4. Not sure. Try to create a small project and I'll check it. It might be a requirement to have closed polygons.
i am including a project that has a polyline body. you can see that it is not rotating.

thanx
 

Attachments

  • B4j Updated.zip
    56.2 KB · Views: 90

Erel

B4X founder
Staff member
Licensed User
Longtime User
Actually i am not deleting the body in the tick event. i am doing it by calling a Sub from a button click. I thought that if i call bw.delete from anywhere in the code it will do the job. So how is the correct way to delete a bodywrapper object including its bodies/joint etc?
The correct solution is to call X2.AddFutureTask and then run the code inside the game loop. Bad things happen when you touch the world objects outside of the loop.

About the polyline, the polyline is a chain of segments. It isn't a physical object. It has zero weight. It is very different than a polygon which is a "full" body.
Polylines are suitable for borders and terrain. They are not replacement for polygons.
 

ilan

Expert
Licensed User
Longtime User
The correct solution is to call X2.AddFutureTask and then run the code inside the game loop. Bad things happen when you touch the world objects outside of the loop.

About the polyline, the polyline is a chain of segments. It isn't a physical object. It has zero weight. It is very different than a polygon which is a "full" body.
Polylines are suitable for borders and terrain. They are not replacement for polygons.
thank you for your reply Erel. The problem with box2d is that it can handle convex polygons but not concave polygons. anyway i create my concave polygon from many other convex polygon fixtures and a polygon made of vertex that is also rotating. the first phase of the game is done now what is needed is to polish the game with animations and nicer menu page, ads, etc.. BUT what i am seeing is a not smooth animation from the bodies that are rotating. i changed the Angle interval to 1 and antialias to false but still the result is not smooth at all and i am not sure it make sense to continue because it feels really bad even though i get 60 FPS. The game feels very glitchy.

do you have an idea what could be the problem?
if you want i can upload the project or send it to you via PM and you can check the results.
 
Last edited:

ilan

Expert
Licensed User
Longtime User
I know that it is not simple to do, but it will be easier if you create a new game project with only this body and upload it.
the code itself is pretty short so i think it will make more sense to upload the project as is. i create the bodies in runtime & graphics in runtime.
the project is 1.6mb so i send you a link to gdrive.

thank you
 

ilan

Expert
Licensed User
Longtime User

Erel

B4X founder
Staff member
Licensed User
Longtime User
I think that it looks better with anti-aliasing.

I see what you are talking about. It is not related to the performance but rather to the drawing interval which is limited to a single degree. With all the straight lines it doesn't look smooth.

Two things that you can try:
1. Add a softer border.

1697016737316.png


This is what I did in the Walking Character example for the rotating blocks.

2. Stop the rotation of the stand once it is under some limit.

Worth trying...
 

ilan

Expert
Licensed User
Longtime User
I see what you are talking about. It is not related to the performance but rather to the drawing interval which is limited to a single degree. With all the straight lines it doesn't look smooth.
yes, this is what i thought. i tried to reduce the drawing interval but it looks like it excepts INT only and 0 stops the rotation. this is a big issue to make games with rotating objects. actually using simple canvas object will look better but i assume i will have performance issue if i use canvas to draw the images.

I think that it looks better with anti-aliasing.
i tried to set anti-alias to true/false nothing really helped.

2. Stop the rotation of the stand once it is under some limit.
i will loose the physic feeling like this. i already reduce the angular dumping value to reduce angular rotation. still it looks really glitchy.


1. Add a softer border.
i am not sure this will fix it.
 

ilan

Expert
Licensed User
Longtime User
How on earth did you come up with an idea like this?!?!
actually, i did not came with the idea. this is lately a popular game. i 3d printed it on my Creality 3d printer for my kids to play and they really liked it so i thought why not create a 2d game of it and started the game but unfortunately the performance for this game on x2 is not what i expected so i abandoned the project but i am working on a new x2 game :)
 
Top