Games Very very very simple Xui2d Test Project

ilan

Expert
Licensed User
Longtime User
ok, now the switches are also working. it is not 100% what i wanted to do but its a working example done in 1-2 days.
it can be improved like rotating the switches in steps (adding 1 deg in tick event to create nice animation) and add more stuff to it.

anyway, i hope you guys like it and i am waiting for the one that will make it run on android or b4i :) (post screenshots please !!)

thanx, ilan

xui2de1.jpg
 

Attachments

  • B4J XUI2D Example 1 C.zip
    124.9 KB · Views: 431

Erel

B4X founder
Staff member
Licensed User
Longtime User
Very nice usage of the Tiled map properties!

I've made some changes and I hope that you are fine with me adding the updated version to the examples pack:

- Using custom types instead of modifying BodyWrapper class.
- The switch movements is done with joints. I started with a revolute joint but it didn't behave as I wanted so I've added a motor joint to make the movement.
- Antialising + angle interval of 1 + rotating objects has an impact on the performance (until the caches are built). I've made some changes to make it lighter.
- Other small changes.


(B4i version)
 

ilan

Expert
Licensed User
Longtime User
Very nice usage of the Tiled map properties!

I've made some changes and I hope that you are fine with me adding the updated version to the examples pack:

- Using custom types instead of modifying BodyWrapper class.
- The switch movements is done with joints. I started with a revolute joint but it didn't behave as I wanted so I've added a motor joint to make the movement.
- Antialising + angle interval of 1 + rotating objects has an impact on the performance (until the caches are built). I've made some changes to make it lighter.
- Other small changes.


(B4i version)


Really awesome erel. It makes me proud to see you updating my example :)

How much changes have you had to do from b4j to b4i? (In the code it self)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
How much changes have you had to do from b4j to b4i? (In the code it self)
The only change that was required after testing it on B4A and B4i is to slightly decrease the tile size as the right and top lines were missing:
B4X:
Dim TileSizeMeters As Float = (X2.ScreenAABB.Height - 0.1) / TileMap.TilesPerColumn

Note that you shouldn't pass ivForeground to TileMap.Initialize. You should instead pass Null:
B4X:
TileMap.Initialize(X2, File.DirAssets, "map.json", Null)
You should only pass an ImageView to TileMap when you use TileMap to draw the background with a tiles layer. It is important as it changes the way the tiles size is calculated.
 

ilan

Expert
Licensed User
Longtime User
Note that you shouldn't pass ivForeground to TileMap.Initialize. You should instead pass Null:

ok i understand, so ivForground is the drawn tilelayer i use in tiled. and what if i am using multiple tilelayers in tiled?

btw in almost all of my games i use tiled i am working with types object to store my object properties.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are not using a tile layer at all in this example. The object layer is not related.

Check Mario example.

All that is required to draw one or more tile layers is:
B4X:
Public Sub Tick (GS As X2GameStep)
   TileMap.DrawScreen(Array("Tile Layer 1", "Tile Layer 2"), GS.DrawingTasks)
End Sub

Public Sub DrawingComplete
   TileMap.DrawingComplete
End Sub
 

ilan

Expert
Licensed User
Longtime User
BTW, the thin lines do not look too good in B4A. You will get better results with more thick lines.

what i normaly do (in android using libgdx and box2d) i store the width and height of the body in my object properties in tiled (if it is a rect) and also the position like this i am calculating in my app the size of the body and draw my sprite to the direction. it would be nice to be able to draw stuff according to my body like i want to. i guess what i will need to do is using a canvas but the question is how the performance on b4i will be. i have tried to use canvas in b4i and the result is very bad this is why i use spritekit for my ios games.
 

ilan

Expert
Licensed User
Longtime User
You are not using a tile layer at all in this example. The object layer is not related.

yes i understand i just asked what IF i would like to draw multiple layer. i also created a tiled lib for b4i and there i can draw any number of tile layers i want.
but your code is much simpler :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
i also created a tiled lib for b4i and there i can draw any number of tile layers i want.
but your code is much simpler
It is also very optimized as the tiles themselves are drawn once and the complete drawn map is reused between frames when possible.

need to do is using a canvas but the question is how the performance on b4i will be. i have tried to use canvas in b4i and the result is very bad this is why i use spritekit for my ios games.
It is better to start a new thread and post more information. You can use Canvas and most examples use canvas for some of the graphics (like the rotating blocks and the score text). You need to be efficient. That means create the graphic once and add it to the graphic cache.
 

ilan

Expert
Licensed User
Longtime User
Deadlock with more than 1000 balls. But the wheel is still spinning... :D

you can limit the number of balls very simply.

B4X:
               If world.AllBodies.Size < 50 Then
                Dim template As X2TileObjectTemplate = TileMap.GetObjectTemplateByName(ObjectLayer, "ball")
                template.BodyDef.Position = X2.ScreenPointToWorld(X, Y)
                TileMap.CreateObject(template)  
            Else
                Log("maximum balls number reached")                  
            End If
 

ilan

Expert
Licensed User
Longtime User
The reason that the wheel keeps spinning is that it is a kinematic body. Kinematic bodies behave like infinite mass bodies and are not affected by collisions.

Dynamic body - is a body that is affected by Gravity. that is why we can apply forces or impulse to it. it can collide with any other body and it requires a lot of calculating process by box2d depends on the shape of it. the fastest bodies to work with as dynamic bodies would be circles. a complex polygon shape will require much more calculating time so it is always a good idea to use a simple shape (if it is possible). it is mostly used for moving objects like player, boxes and anything else in the game that should move around.

Static body - is a body that cannot move. you cannot apply forces to it or set any velocity to it. it doesn't require a big calculating process and it doesn't collide with other static bodies or kinematic bodies. mostly used for walls, ground, or anything that should not move in a game.

Kinematic body - is something between dynamic and static body. it is not affected by gravity but you can set a velocity to it. angular (rotating) or linear velocity. a good example of using a kinematic body in a game is like lift, elevator, moving grounds, gears,... objects that should only move around but not be affected by gravity or forces on it.

Note that you can transform anybody with Body.SetTransform(..,..) but this is not the way to use box2d. you will lose the physic filling. so make sure to move bodies only by adding forces/impulses to it or setting his velocity parameter.
 

sorex

Expert
Licensed User
Longtime User
nice, Ilan.

I didn't know this was a quick remake of an existing game which I saw passing by this weekend.

Well done.
 
Top