Games [XUI2D] Space Invaders #2


B4X founder
Staff member
Licensed User
Longtime User

Resources are based on:

Previous example:

New features in this example:

- shields
- mystery enemy (red enemy)
- high scores
- explosion graphics
- and some other small improvements.

If we run the game with debug drawing then we can see that the shields are made of many small fixtures:


This allows us to destroy small parts of the shields. See the code in the Shield class.

There are three new methods in X2Utils:

- AddFutureTask2 - Similar to AddFutureTask. Allows to add duplicate future tasks. Duplicate means FutureTasks with the same Callback, SubName and Time.

- GetBodyWrapper - Returns a X2BodyWrapper based on the Id. The Id field is a new field that is set from the tile map object id. You can also set programmatically.
- GetBodiesWrappers - Returns a list with all bodies with ids listed in the ListOfIds parameter.

I'm using GetBodiesWrappers instead of the Enemies list that was maintained in the previous example. The advantage is that we don't need to worry about the list not being synchronized and we let XUI2D maintain it for us.

Example projects included in the examples pack:
Last edited:


Active Member
Licensed User
Longtime User
What, or what version of it, am I missing with this compile-time error?

B4J Version: 6.30
Parsing code.    (0.04s)
Compiling code.    (0.33s)
Compiling layouts code.    (0.02s)
Organizing libraries.    (0.00s)
Compiling generated Java code.    Error
B4J line: 184
MainBC.FillRect(xui.Color_Transparent, MainBC.Tar
javac 1.8.0_171
src\b4j\example\ error: cannot access B4XCanvas
  class file for anywheresoftware.b4a.objects.B4XCanvas not found


B4X founder
Staff member
Licensed User
Longtime User

A small update with three changes:

- X2TileMap now respects the rotation property.
- The ship rotates based on its X position.
- The lasers are fired based on the ship angle. This is done with a new method in B2Transform named MultiplyRot. It multiplies the vector with the transform rotation matrix. The result is a rotated vector:
template.BodyDef.Angle = bw.Body.Angle
template.BodyDef.LinearVelocity = bw.Body.Transform.MultiplyRot(x2.CreateVec2(0, 5))

Note that it depends on XUI2D v0.95 which was not yet released.


  • B4J
    445.5 KB · Views: 434