- The ship movements is managed in the same way it is managed in the Space Shooter example. A motor joint moves the ship to the touch position.
In B4J it can also be moved with the keyboard.
If touch.IsInitialized = False Then ShipMotor.MaxMotorForce = 0 'disable the motor Else 'the touch panel is wider than the game screen so we need to fix the offsets and clip the value to the game screen (ivForeground) Dim x As Float = Min(ivForeground.Width, Max(0, touch.X - (ivForeground.Left - PanelForTouch.Left))) Dim v As B2Vec2 = X2.ScreenPointToWorld(X, touch.Y) ShipMotor.LinearOffset = X2.CreateVec2(v.X, ShipMotor.LinearOffset.Y) ShipMotor.MaxMotorForce = 50 End If
There is also a check for the total speed and the ball is pushed if it is too slow.
- The spritesheet is a bit strange and requires some work to extract the correct images.
- No doubt that moving to B4XPages makes the game lifecycle simpler.
I've used the resources from Ilan's example: https://www.b4x.com/android/forum/threads/game-making-video-series.130388/. Thank you Ilan!
Example is available in github: https://www.b4x.com/android/forum/threads/xui2d-x2-v2-0-2021.131279/#content