iOS Tutorial Porting (game) from B4A > B4i and the differences

Hello,

Last night I ported a small game (CLAUStrophobia) from B4A > B4i just to get used to B4i & IOS and to know the differences in the B4i language & OS.

As I ran into some issues and some other things I will list the differences in this post as it might help people who will go throught the same progress/process.

As my project was mainly (selfwritten) class based I expected a lot of rewriting but to my surprise it was only a minimum.

Let's start with what I still remember :)


Designer
The designer is simular but has a lot more settings for the main page (which is B4A activity like)
It would be nice if B4i could import a B4A BAL file to grab the structure and views that are simular.
I had to recreate everything and keep an eye on the right tags, sizes etc where my code relies on
but since I only had 3 panels and a handfull imageviews this was ok.

Activities
This doesn't seem to exist in B4i but these are called pages.
All it needed was changing the dims types in globals & subs from activity to page.

Bitmaps
DrawBitmap doesn't have a source rectangle option so you have to use clippaths
Invalidate doesn't exist either and you need to use Refresh (why was this not renamed to invalidate?)

Maps
Here I was not able to use a counter based loop to go through the list due to the lack of .GetKeyAt()

B4X:
'B4A method
For k=mymap.Size-1 To 0 Step -1
 kd=mymap.GetKeyAt(k)

The only way that seems to work is with

B4X:
'B4i method
For Each k As String In mymap.Keys
 kd=mymap.Get(k)

The rest for reading, storing and updating is the same.

Panels
The touch events are not working when using a hidden panel by setting alpha=0.
The minimum it needs is 0.02, 0.01 didn't work either.
A 'workaround' is using a transparent background color and alpha 1 or something >=0.02.

Subs
My class has some subs that return values based on math.
This only worked right when I declared/defined all the parameter and return types in the sub definition or in the sub. (not needed in B4A)

B4X:
sub mysub (a as int) as int
 dim b as int
 b=1
 return a+b
end sub

Regex.split
IOS don't allow "" as delimiter to have a string split to an array based on each character.
You can user .charAT instead but keep in mind that casting won't work to INTs.
I used charAt to a temp string variable and then store that tempstring in the INT variable which works.


Conclusion:

from the +/- 600 lines of code (incl. classes) I had to modify only a (few) dozen(s) of lines once I knew what was going on or missing.

stuff like:

code based view creation, removal, resizing, positioning
math
arrays
if/then's
timers
...

were working right from the first time.

so in general depending on the project you might be as lucky as me (I only used the core lib tho)
and be able to have a project ported in a few hours.
 
Last edited:

sorex

Expert
Licensed User
Longtime User
indeed, Klaus.

a list named mymap doesn't make much sense ;)

I'll change it.
 
Top