# Libraries For Bullet Hell?

Hey,

I’m trying to make a bullet hell shooter in Haxe (using Stencyl). I’ve made a fair amount of progress, but I’ve run into a performance barrier with the amount of bullets I want. I’ve been wrestling with this problem on Stencyl’s Discord for a while, and at this point we feel like the best option is to use a third-party library.

I’m now trying to find the best library for this. I ran across Barrage on Github, but it’s still in development, and the last commit was eight months ago, so I doubt it’ll be finished soon. What I’m looking for is very high performance, while still being flexible enough to do some fancy stuff.

Does anybody know about a good bullet hell library?

I’m not sure how much sense this makes, but if it needs some elaboration on a certain point, I’ll do my best.

Thanks!

You first need to know where is your performance choke:

• Is it rendering the bullets?
• The answer then resides in the Tilemap class.
• Is it in the collision logic?
• (If you are using circular collision check the sum of the square of the radius instead of the actual radius. Math.sqrt() is somewhat expensive)
• Investigate about “broad phase collisions” like quadtrees or hashtables.
• Is it in calculation of the path/trajectory of the bullet?
• Maaaaaayyyyyybe if you can parametrize the movement and analyze a function with time as your independant variable you can optimize it, but this one is the one I am less sure about

The way I’m doing it now is by coinciding an image with a bunch of arrays (X Position, Y Position, Angle, Speed, Grazed?, Tweening? (for whether or not the bullet is current doing it’s create tween), Image Instance, Bullet Type, and a couple others I can’t remember off the top of my head).

Removing the images from the program does boost performance a fair amount, but not nearly enough. I need approximately a tenfold improvement, which would result in about ~2000 bullets. Are tilemaps rotateable? I seem to remember reading somewhere that tilemaps weren’t rotateable, which immediately made me drop that idea.

I am doing radial checks at the moment for collision, though I’m not sure what you mean by checking the sum of the square root. Wouldn’t that still require Math.sqrt()?

Tiles/TileContainers are almost equal to display objects. The only things you don’t have are: Vectorial graphics, masks and event listeners

Instead of comparing the radius with the distance (to get the distance you had to use sqrt) compare the radius squared (radius * radius) with the distance squared (don’t do the sqrt in the distance calculation).

Also something that might be important, try to use object pools if you are not using them. Creating lots of objects and then deleting them can be expensive.

`graphics.drawQuads` is another newer API which is designed to handle batch rendering

Hello,

I’m using CannonML, there’s a library for haxe, you can find it on haxelib (here). I run accross some issues but now it’s working fine for me. It’s like BulletML but with a more complex syntax.
Example… :
[l\$1=\$i?(360) ht\$1 f6 ht\$1+5 f5 ht\$1-5 f5 ht\$1 f4 w5]

It manages all the movements, rotation, creation (barrage etc.) of bullets BUT NOT the rendering and the collision. So you manage the collision with the library you want, same for the rendering.
It’s using pooling also.

It can also manage the enemies.

The official documentation has disappeared for the syntax of cannonML, I made a local backup, you can download it here with a workbench and the Haxe library :

13rice: Thanks! I took a look at the workbench for CannonML, and it looks pretty promising. Is it compatible with desktop? It says that it’s for Flash, which would be a bit of a problem, as I’m developing for desktop.

How many bullets can it support before the framerate starts dipping? And is it possible to do game mechanics like grazing with it?

miltoncandelero: I’ve found a Tilesheet class in Stencyl’s API, and I’m discussing it with Stencyl people atm. I changed my sqrt code to check the sum of squares, and it helped a bit, but not too much.

singmajesty: I haven’t looked into drawQuads yet, but if CannonML is good, I’ll probably try that.

Here’s a SampleProject in CML with Haxe
I’ve started from this sample to understand the syntax and how the library can work with OpenFl
Once you mastered the syntax it’s really powerful for making complex patterns. Use this sample to make a stress test and try different rendering (drawQuads, Tile etc.)

Like I said it’s a library for the bullet patterns, NOT the rendering and NOT the collision.
I think the best for rendering it’s Tiles, personnaly I use Tile. I don’t have 2000 bullets and never made a stress stest, my bottleneck is more on collission (box2d…). Sample video from my game

I think first version of CML has been made in AS3, it has been ported to Haxe by gunnbr (thanks to him !). In haxe you can use any target, so no problem for windows. For my game it’s android, flash and html5. Works also for Windows.

Okay, that’s good to hear. I’m having some trouble implementing it into my engine, but I should be able to figure it out with some help from the community.

Can I access where each bullet is? If I can, collision and stuff like grazing should be a breeze.

Here is my on going project … https://www.youtube.com/watch?v=XndXJ7QejwQ. its Shump semi bullet hell… I am using a SWF assets for this one, But might change it to tilesheet approach.

I’ve managed to implement Tilemaps into my game. I’ve also managed to access CannonML in my engine, but I’m not sure how to coincide the Tilemap rendering and the CannonML bullets. Without the rendering, I also can’t tell if CannonML is actually making bullets or not, which is a big problem.

Can anyone help with this? Or should I open a new thread for this?

Try to round bullet coordinates and test the difference in performance with thousands instances.

I can have more than two thousand tile instances on screen at once, which is about what I think I’ll need. My problem now is trying to match all the tile instances to a respective CannonML bullet, so that I can actually see what CannonML is doing, if anything.

You have callbacks from CannonML to notify when a bullet is created, in the CMLObject class. You should have a class extending CMLObject, let’s call it Bullet, for bullet creations and the bullet itself.

• onFireObject(args) : trigger when the Bullet creates a new child Bullet, important, you can use “args” for the link with your engine
• onCreate : the Bullet is created
• onUpdate : the Bullet is updated, if you have an animation for example, you update it here
• onDestroy : the Bullet is destroyed, remove it from your engine, paly a sound, launch a fx etc.

So to make the link with your engine :
First option : for each creation of Bullet in the CMLScript, you set an ID, like :

`f3{1}`
It will create a single Bullet, speed 3, and send “1” in the args array of onFireObject. So in your engine you can match this “1” with whatever you want, it’s like an ID.

Second option (mine) : maybe more tricky, you create a Bullet, with a given Label ID (see Label in the workbench), so you know in advance what kind of bullet it will produce, it’s like an emitter.
`#SQUARE_BULLET { [f3 w10]5 }`

To launch the emmitting sequence, add a “start” function like this

``````public function start():Void
{
execute(cmlScript.childSequence[_labelID]);
}``````