B4i Library iTiled (for iSpritekit)

hi,

with iTiled you will be able to import Tiled .tmx files to your B4i (iSpritekit) project.
it is much more simpler to create games with Tiled.

you can even create menu scenes or shop scenes and not only the game scene itself.

what is possible with iTiled:

- create single/multiple Tile Layers.
- create single/multiple Tilesets with same or different tile size.
- create single/multiple Object layers.
- All 4 Objects types are supported (rect, ellipse, polygon, polyline)
- polygon and polyline will return a List with all vertices.
- you can uncheck layers to exclude them from importing
- very good performance!
- use custom object properties and import them to your project.

object list returns a type object:

B4X:
    Type TileObj(objtype As String, name As String, id As Int, x As Float, y As Float, width As Float, height As Float, rotation As Float, vertices As List, myproperties As Map)

using iTiled is very simple.
you create a Sknode that will hold all tiles on it and will draw everything you created in tiled.
then you get a list with all objects and create of them you sknodes with physicbodies (like you do in android)

first, you need to initialize the sknode that will hold all tiled nodes:

B4X:
    'Initialize Skspritenode
    myTileNode.Initialize("myTileNode")
    myTileNode.Position = Functions.CreatePoint(0,0)

then you initiaize iTiled with the sknode:

B4X:
    'SetUp TileMap (TILED)
    iTiled.initialize("level1.tmx",myTileNode)

after that if your tmx file contains Objects you can import them by going in a loop through the public object list:

B4X:
For i = 0 To iTiled.ObjectList.Size -1
'....
Next

VERY IMPORTANT:

- .tmx file AND png tileset image need to be in your Files/ Folder (not in Special Folder!)
- use only CSV tile layer format
- use only "Based on Tileset image" (and not collection of images)
- draw only what you have to draw. it is better to draw the backround without Tiled!

this is a beta version so if you have any issues please report them and i will try to fix everything.
if you like iTiled then please consider a donationbut this is not necessary so iTiled is free to use :)

if you have a local mac then you need to copy the .a and .h files to your local mac. the .xml file needs to be copied to your windows library folder.

if you are using a hosted mac you need to copy only the .xml file to your windows library folder and wait until @Erel will upload the .a and .h files to the hosted builder.

thank you, ilan

EDIT: 04/02/2018, i have updated iTiled and fixed a lot of bugs. i have also included an example that loads correctly the created objects from your tiled.tmx file. you can easily create physics bodies from those objects by using their vertices (path), width, height, x, y,...

 

Attachments

  • iTiled 0.2.zip
    203.7 KB · Views: 19
  • Example v0.2.zip
    55.7 KB · Views: 18
Last edited:

ilan

Expert
Licensed User
btw i am using a Functions code module in my projects thats why you have in the code above:

B4X:
myTileNode.Position = Functions.CreatePoint(0,0)

so just create a code module named "Functions" and copy this code:

B4X:
'Code module

Sub Process_Globals

End Sub

Public Sub CreatePoint(X As Float, Y As Float) As Point
    Dim aPoint As Point
    aPoint.Initialize(X,Y)
    Return aPoint
End Sub
Public Sub CreateVector(Dx As Float,Dy As Float) As Vector
    Dim aVector As Vector
    aVector.Initialize(Dx,Dy)
    Return aVector
End Sub

Public Sub CreateSize(Width As Float, Height As Float) As Size
    Dim aSize As Size
    aSize.Initialize(Width,Height)
    Return aSize
End Sub

Public Sub distance(x1 As Float, x2 As Float, y1 As Float, y2 As Float) As Double
    Dim dX = x2 - x1 As Double
    Dim dY = y2 - y1 As Double      
    Return Sqrt((dX * dX) + (dY * dY)) 'simple distance calculation
End Sub
 

ilan

Expert
Licensed User
hi everyone, for my new b4i app i am using iTiled in a more advanced way and i found lots of bugs. so i fixed a lot of them (i hope all) and i will keep working on it and see if i find more bugs.

i will update the first post soon and also the example project so i just wanted to let you know if you are using iTiled in a running project that it will be updated soon and you should update it too.

btw. who is going to use this lib? anyone working on a b4i iSpritekit game?
i made another library that i want also to share with you guys, its called iAtlas. with iAtlas you can create Atlas sprite-sheets images and get them from that sheet instead of having all images separately in your files folder. (like this it is much more organized!)

EDIT: post #1 has been updated with the latest iTiled version + example project.
 
Last edited:

sorex

Expert
Licensed User
anyone working on a b4i iSpritekit game?

not really but I'm having issues to draw a tiled like map to a canvas (the weird lines thread from 2 days ago).

so a tutorial or example on how to display a tile based screen/map with spritekit might be handy.
 
Top