Games [XUI2D] Example Pack

Status
Not open for further replies.

Erel

B4X founder
Staff member
Licensed User
Longtime User

Gunther

Active Member
Licensed User
Longtime User
Dear Erel,

well I saw in all your examples that left and right from the pricture the background is always visible? May be a typo in the designer script:

When GameRatio replaced by ScreenRatio - this spaces are gone! (here modified setting)


Here Mario with GameRatio (original setting):


and with ScreenRatio (modified setting):


What you think? Is it locally at my phone or as one can see in your exapmle videos with spaces intendet?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Updated "Ilan's first app" example. The balls are created with random colors instead of being loaded from an image file:



The relevant code is:
B4X:
'returns the graphic name
Private Sub CreateCircleForBall (Shape As B2Shape) As String
   Dim ballsize As B2Vec2 = X2.GetShapeWidthAndHeight(Shape)
   'we could have used B4XCanvas here instead of BitmapCreator.
   Dim bc As BitmapCreator
   bc.Initialize(X2.MetersToBCPixels(ballsize.X), X2.MetersToBCPixels(ballsize.Y))
   'inner circle
   bc.DrawCircle(bc.TargetRect.CenterX, bc.TargetRect.CenterY, bc.mWidth / 2 - 2, Rnd(0xff000000, -1), True, 0)
   'outer circle
   bc.DrawCircle(bc.TargetRect.CenterX, bc.TargetRect.CenterY, bc.mWidth / 2, xui.Color_Black, False, 2)

   Dim sb As X2ScaledBitmap
   sb.Scale = 1
   sb.Bmp = bc.Bitmap
   'add to cache
   Dim gname As String = X2.GraphicCache.GetTempName
   'the balls are simple circles so there is no reason to "rotate" them. Setting AngleInterval to 360 disables rotation.
   X2.GraphicCache.PutGraphic2(gname, Array(sb), True, 360)
   Return gname
End Sub

Creating many temporary graphics can harm performance as they are not reused between different bodies. In this case it is not problematic as the circles are never rotated.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've made a relatively large update.

objecttypes.json was updated as well. Its version is: 0.98



There is a new property named 'nearest neighbor scaling'. This is an alternative resizing algorithm which in some cases produces better results. It is used in the angry birds example for the hook and the bricks.

Some changes were made in X2SpriteGraphicCache. There is a new PutGraphicBCs that accepts a list of BitmapCreators, instead of a list of X2ScaledBitmaps.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The example pack was updated. Using the new b4x libraries feature, all the X2 modules (and the objecttypes.json file) are now packed as a single b4x library named X2.
It is available here: https://www.b4x.com/android/forum/threads/b4x-x2-xui2d-box2d-game-engine.95208/#post-601674

1. You need to use B4A v8.80+ or B4J v7.0+ or B4i (TBD).

2. Download the X2 library and copy it to the additional libraries folder.

The source code of the X2 modules is available in the included X2 Source Code project.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…