Jump to content

bullet problems. (group.total == group.length == countLiving(), and outOfBoundsKill)


Lutcikaur
 Share

Recommended Posts

So ive been debugging some code off of the tanks bullet example. I dont know how many bullets will be fired at once, but i want to always have a reasonable amount available.

 

the following code is run on player initialization 

bullets = game.add.group();bullets.createMultiple(30, 'bullet');bullets.setAll('anchor.x', 0.5);bullets.setAll('anchor.y', 0.5);bullets.setAll('outOfBoundsKill', true);

and on fire the following code is run.

if(game.time.now > nextFire) {	var num = bullets.countLiving()+bullets.countDead();	if(bullets.countLiving() > num/2) {		bullets.createMultiple(num, 'bullet');		bullets.setAll('anchor.x', 0.5);		bullets.setAll('anchor.y', 0.5);		bullets.setAll('outOfBoundsKill', true);	}	nextFire = game.time.now+fireRate;	var bullet=bullets.getFirstDead();	bullet.reset(knight.x,knight.y);	bullet.rotation=game.physics.moveToPointer(bullet,500);} 

After logging the values of bullets.total, bullets.length, and bullets.countAlive . . . they all return the same values.

Im using dead+alive to do my calculation... but the documentation makes it seem like total or length should be the one i use (and that somehow they are different)

 

Also.. outOfBoundsKill varies wildly. firing from where my character spawns every 100ms, for 30 bullets that move at 1000 "rate", i fire for 3 seconds(ish) then wait three seconds, then i can fire again. Thats okay. But if i fire and walk with the bullets, at say 500, the same firing pattern wont happen. the bullets stay alive for a much longer period of time,  leaving me with longer 'dry periods' without having bullets fire. If i move fast enough , having bullets travel at 500 and my character moving at 500, the bullets stay alive for as long as im with them.

 

I must not be understanding something correctly.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...