Collision and overlap in a tilemap problem.

  • Hi, im new to haxeflixel ( and programming mostly) and im stuck with a problem in a TD game im trying to create.

    Im trying to spawn enemies from _spawn, find a path to _player, and get killed once they touch _player. Up to this point, eveything was fine, but when i added a tilemap flxg.overlap and flxg.collide either don't work, or break the tilemap.

    my problem

    I've noticed overlap gets called every frame, so it's checking collision with the map itself i believe, not with the Player entity.The .kill() method is also breaking it in other version of this same problem (calling a die function in the Enemy class, wich is just super.kill();).

    So my question is, how do i check for collision between _enemy (wich comes from a group) and _player in my situation? Is there a simple answer that im missing?

    Im being flagged as spam when i try to post code or links, so ive put some of my code here: and here

    Thank you for reading my problem guys.

  • The problem is you don't add new enemy to enemyGroup.

    Hold on! I'm on my phone and I'm writing a more detailed answer.

  • Thank you for the quick reply man, sorry i cant put more links or code, im being flagged spammer when i try, lol.

    I thought i added enemies here:

    	var enemies = new FlxTypedGroup<Enemy>();
    	_enemy = enemies.recycle(Enemy);
    	_enemy.setPosition(_spawner.getPosition().x, _spawner.getPosition().y);

    • Take a look at the first block of code in spawnEnemy()
    		//enemy group
    		var enemies = new FlxTypedGroup<Enemy>();
    		_enemy = enemies.recycle(Enemy);

    You already have enemyGroup, you don't need to create a new enemy group anymore.

    Hence it should be

    		// var enemies = new FlxTypedGroup<Enemy>(); delete this
    		_enemy = enemyGroup.recycle(Enemy);
    • And at the third block:
    		add(_enemy); // this only adds the enemy to the state not enemyGroup
    		_spawnCounter = 0;
    		trace("enemy spawned");

    Replace the first line with:

    • For all of that to work, you forgot/need to add this in create():
    enemyGroup = new FlxTypedGroup<Enemy>()

  • I tried it and it works perfectly!!

    Seriously thank you so much for using up your time to explain this to me, now it seems so simple, haha.

  • By the way:

    _spawnCounter +=;
    if (_enemiesToSpawn > 0 && _spawnCounter > _spawninterval * FlxG.updateFramerate )

    Maybe you want:

    _spawnCounter += elapsed; // _spawnCounter need to be Float
    if (_enemiesToSpawn > 0 && _spawnCounter > 2) // spawn every 2 seconds for example
    • FlxG.timeScale is used to change the speed of the game and it's 1 by default.

    • New forum users can't post many posts in a short time.

  • I wanted to have a fast foward like Defenders Quest, so i thought that linking spawn rate to framerate was the way to go.

    Am i overthinking it (its a solution from the TD demo)? Maybe seconds is simpler, i'll try it out. Thank you.

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.