Can't See Bullets



  • So I just picked up HaxeFlixel this weekend and am trying to make a sort of top down shooter similar to Binding of Isaac. Currently I am trying to get the player bullets working but although they collide with the world properly, they are never visible. I have a feeling it has to do with how I am using FlxTypedGroup. As you can see from my code, I went through all but the combat portion of the RPG tutorial found on this website so perhaps that could be causing a problem as well. All the relevant code is on PlayState.hx and the Bullet.hx.

    src: https://www.dropbox.com/sh/lp75cn2dgu0myql/AABnZvYQLoLr-Btt_ybVjRtra?dl=0

    Thanks!


  • administrators

    First off, you need to add() the bullet group to the state. That call is already there, but commented out, so I guess you experimented around with that.

    The main issue is that the bulletHitMap callback triggers immediately. The reason for this is described in the docs for FlxG.overlap() (http://api.haxeflixel.com/flixel/FlxG.html?#overlap):

    NOTE: this takes the entire area of FlxTilemaps into account (including "empty" tiles). Use FlxTilemap#overlaps() if you don't want that.

    In this case, you can just replace the call with collide() instead of overlap():

    FlxG.collide(_grpBullets, _mWalls, bulletHitMap);
    

    Some other things to note regarding recycling:

    • You don't need to initialize _grpBullets with 30 Bullet objects. recycle() automatically creates instances.

    • For recycled objects, the initialization logic is typically put into a separate init() method, not the constructor. This way, you can call init() after the recycle() call:

      var bullet = _grpBullets.recycle(Bullet);
      bullet.init(_player);
      


  • @Gama11 Great that did it! Thank you for the quick and thorough response.