Very nice!
I see several things that should be improved in the X2 framework.
1. There was an extra space in one of the graphic file names. This causes the program to crash in release mode. I will change X2TileMap to trim extra spaces.
2. X2BodyWrapper.TemplateCustomPropertieswill returns a Map with the custom properties set in Tiled. This allows you to add more properties.
3. There are several ways to change graphics. The simplest way is to set multiple "graphic files":
If 'switch frame interval' is set to 0 then the graphics will not change automatically.
This will allow you to manually change the current frame:
Dim Sw As SwitchData = Switch.Tag
Sw.State = Not(Sw.State)
If Sw.State Then
Switch.CurrentFrame = 1
Else
Switch.CurrentFrame = 0
End If
4. Your code for finding the touched body is not very efficient. Especially if there will be many bodies. A more efficient solution based on box2d internal tree of AABBs:
Sub TouchedSwitch(x As Float, y As Float) As X2BodyWrapper
Dim aabb As B2AABB
Dim vec As B2Vec2 = X2.ScreenPointToWorld(x, y)
aabb.Initialize2(vec, vec)
For Each body As B2Body In world.QueryAABBToMapOfBodies(aabb).Keys
If body.FirstFixture.Shape.TestPoint(body.Transform, vec) Then
Dim bw As X2BodyWrapper = body.Tag
If bw.Tag Is SwitchData Then
Return bw
End If
End If
Next
Return Null
End Sub
The second check is required as the first test doesn't consider the actual shape. Only the bodies AABB rectangle.
5. There was a bug in X2.GetBodiesFromContact that could caused the game to crash in an edge case where the body is deleted during the contact. Fixed.
6. About the non-smooth lines. There is currently a limit for the maximum graphic size that is being antialiased. The size is set to 300. I'm not sure that it shouldn't be changed to a much higher value. For now you should change the limit yourself in X2SpriteGraphicCache:
Public const MAX_SIZE_FOR_ANTIALIAS As Int = 300 'change to 800
Note that it would have probably looked better in B4A and B4i.
7. The usage of tags is fine. However it would not have been required if you used a class for the balls and the switches. It is up to you.
A modified example is attached. It is based on the standard X2 classes without any modifications.