Games [XUI2D] Space Invaders #1

Discussion in 'Game Development' started by Erel, Aug 17, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User


    A simple example of classic space invaders.
    Resources are based on:

    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:
    Last edited: Aug 23, 2018
    scsjc, Peter Simpson, LucaMs and 12 others like this.
  2. sorex

    sorex Expert Licensed 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).
  3. Erel

    Erel Administrator Staff Member Licensed 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:
    X2.TargetFPS = 30
    Last edited: Aug 17, 2018
    Peter Simpson likes this.
  4. sorex

    sorex Expert Licensed 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.
  5. sorex

    sorex Expert Licensed 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)
  6. Jaames

    Jaames Active Member Licensed 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


    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.. :)
    LucaMs and Erel like this.
  7. Erel

    Erel Administrator Staff Member Licensed User

    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.
    inakigarm and Jaames like this.
  8. LucaMs

    LucaMs Expert Licensed 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: Aug 18, 2018
  9. LucaMs

    LucaMs Expert Licensed User

    I must say that it is not easy to find the latest versions of some libraries, in this case jBitmapCreator:

    Updates to internal libraries:

    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:

    Last edited: Aug 18, 2018
    Johan Hormaza and MallyUK like this.
  10. Peter Simpson

    Peter Simpson Expert Licensed 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: Aug 18, 2018
  11. sorex

    sorex Expert Licensed 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.
  12. LucaMs

    LucaMs Expert Licensed User

    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
  13. LucaMs

    LucaMs Expert Licensed User

    next challenges:

    1) being able to move your spaceship even vertically;
    2) - more important - add a scrolling background, to see at that point what would be the speed (fps).
  14. sorex

    sorex Expert Licensed User


    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: Aug 19, 2018
  15. Erel

    Erel Administrator Staff Member Licensed User

    Peter Simpson likes this.
  16. LucaMs

    LucaMs Expert Licensed User

    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.

    My benchmarks rank Huawei P8 Lite 2018 third; maybe because... it is my smartphone and I'm lying! :p
    Last edited: Aug 19, 2018
  17. sorex

    sorex Expert Licensed User

    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.
  18. Erel

    Erel Administrator Staff Member Licensed User

    B4X apps performance is similar to the performance of apps written in Java or Objective C.

    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.
    Johan Hormaza likes this.
  19. Erel

    Erel Administrator Staff Member Licensed User

    Not the place to discuss it but you should set the restitution to 0 if you don't want objects to bounce.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice