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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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