Games [XUI2D] Space Invaders #1

Erel

B4X founder
Staff member
Licensed User
Longtime User
SS-2018-08-17_11.32.54.jpg


A simple example of classic space invaders.
Resources are based on: https://github.com/leerob/Space_Invaders/

The various objects are defined with Tiled map editor.

Interesting points:

- No gravity.
- The lasers 'is sensor' property is checked. This way they don't push the collided object.
- The enemy laser 'category bits' is set to 2. The enemies 'mask bits' is set to 65533 (Bit.And(0xffff, Bit.Not(2))). This way the enemy laser doesn't hit the enemies.
- The enemies change direction when one of the enemies touches the edges.
- The ship linear damping is set to a high value. This causes the ship to slow down although there is no friction.

Example projects included in the examples pack: https://www.b4x.com/android/forum/threads/xui2d-example-pack.96454/
 
Last edited:

sorex

Expert
Licensed User
Longtime User
Sweet :)

But it seems that java + box2d are not a good match for games like this.

It pulls down an entire core for something simple like this (yes in release mode).
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
What do you see? It runs smoothly here in 60 fps. It can temporary switch to 30 fps however it will quickly go up to 60 FPS again.
You can force it to run at 30 FPS. The difference in the look and feel will be small.
Add this line in Game.Initialize after X2 is initialized:
B4X:
X2.TargetFPS = 30
 
Last edited:

sorex

Expert
Licensed User
Longtime User
it only is 'static' around 30-33FPS but sometimes it shoots up to 40+ but since that goes as quick down as it went up I can't tell it it was 45 or 49.
 

sorex

Expert
Licensed User
Longtime User
when I remove everything exept ivforeground & lblstats from the designer and the related code then it's constant between 58-60fps.

it appears that the overlays cause a lot of slow down here even when no real alpha's are used. (I disabled a few)
 

Jaames

Active Member
Licensed User
Longtime User
Here it is running on the relatively old PC and it run flawlessly, with 2 monitors , and HD YT video on second monitor playing. and bunch of other programs in background.

PC Intel i7 3770 @ 3.4Ghz
16 GB RAM
NVIDIA GeForce GTX 680

1.jpg

I know "the like" is enough , but I have to say, thank you @Erel for amazing framework , every time you release new version it is more and more easier to use and more appealing .. And to be able to use it on all 3 major platforms without changing any code is bringing B4X tools to another level.. :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
it only is 'static' around 30-33FPS but sometimes it shoots up to 40+ but since that goes as quick down as it went up I can't tell it it was 45 or 49.
I will write a more thorough tutorial about performance. The X2 framework will very quickly lower the drawing FPS to 30 if it cannot keep with 60 FPS (once it falls to 55 FPS). Even if it is a momentary slowdown.

It will keep running in 30 FPS and try to push back to 60 FPS after a specific period. I actually plan to make some changes in the way this period is calculated.

The bottom line is that it is fine if a game falls to 30 FPS. It will be a bit less smooth but should still look good.
 

LucaMs

Expert
Licensed User
Longtime User
The B4J Tutorial - B4J Change Log (version history) should be updated (6.30 --> 6.50).
P.S. Ok, now I understand, 6.50 is a beta version (I saw this only now).

About FPS: did you test it on Android? Not me (not even the b4j version, given that I got the message... see above :D)
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
The B4J Tutorial - B4J Change Log (version history) should be updated (6.30 --> 6.50).

About FPS: did you test it on Android? Not me (not even the b4j version, given that I got the message... see above :D)

I must say that it is not easy to find the latest versions of some libraries, in this case jBitmapCreator:
upload_2018-8-18_12-7-46.png



Updates to internal libraries:
upload_2018-8-18_12-9-2.png


In B4J 6.50 Beta BitmapCreator is version 4.00.

In the BitmapCreator thread (which I would rename by removing "Pixels, drawing and more", leaving only "BitmapCreator"):
upload_2018-8-18_12-17-18.png



I think the zip file names should include the version number.

For the moment I could not find version 4.15 (and I suppose it is for this reason that I get errors opening the source of SpaceInvaders in b4j 6.50 beta - B2Vec2).
P.S. found:
upload_2018-8-18_12-41-12.png


:p
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Hmm I've just seen this new post @Erel,
hey congratulations on the whole XUI2D project, it's looking great. This Space Invaders game is running ridiculously smoothly and consistently at betweek 58FPS and 60FPS, and congratulations to you on me not getting past level three on my first attempt.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
nope, will try it later today.

but fps is one thing, cpu usage another. I don't know how I can see that on an android.
Well, I think that you can reach high fps depending on cpu (and ram and other, like graphic card).

I wanted to try an Android version, but I sweated to find the libraries and I do not know how much I should sweat to create the app version :p
 

sorex

Expert
Licensed User
Longtime User
Luca,

the new version on android starts at 58-60fps but drops after a second or 2 to 30-33.

When you create a gap between the aliens and shoot there than the fps goes up to 55+ fps again till the aliens get near again.

Some times when there is only the player and its bullets are left + 1 moving enemie it's also running at 30fps.

It's hard to see a line in the fps decreases.

But for the eye I believe that 24fps is enough to create smooth animations.

Edit: forgot to mention that this is on a Huwaei P8 Lite phone
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User

LucaMs

Expert
Licensed User
Longtime User
the new version on android
I have to find search for it :)

I'm not a videogame expert, not even as a player.
I always thought that to develop fast games it was necessary to work at "low level" and that the Basic was not a suitable language.
All this framework probably will not reach the same speed as other approaches but it greatly simplifies development and this is probably a greater advantage in many cases.

Edit: forgot to mention that this is on a Huwaei P8 Lite phone
You can see the device performance score here: https://www.androidbenchmark.net/passmark_chart.html
My benchmarks rank Huawei P8 Lite 2018 third; maybe because... it is my smartphone and I'm lying! :p
 
Last edited:

sorex

Expert
Licensed User
Longtime User
All this framework probably will not reach the same speed as other approaches but it greatly simplifies development and this is probably a greater advantage in many cases.

It depends what you want to do ofcourse. this Xui2D is powerfull but oh so difficult to get used to.
It doesn't seem like really simplifying it code wise tho as you need to take care of a lot compared to some other (simple) 2D methods.
You will also witness some unexpected side effects when you'll start experimenting with it.
For example drop a box pure vertically onto another one and it will move horizontal aswell or rotate where you expect that it would just stop on top of the other one.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I always thought that to develop fast games it was necessary to work at "low level" and that the Basic was not a suitable language.
B4X apps performance is similar to the performance of apps written in Java or Objective C.

You will also witness some unexpected side effects when you'll start experimenting with it.
For example drop a box pure vertically onto another one and it will move horizontal aswell or rotate where you expect that it would just stop on top of the other one.
Please start a new thread and describe any issue you encounter. This is exactly the purpose of the beta versions.
About the complexity, you need to learn about Box2D in order to understand XUI2D.
 
Top