I've just done a quick test and it seems a small number of objects aren't being deleted.
No I'm not creating bullets every loop. Bullets are only created if isShooting == true, which is true when the left mouse button is held down. There's also a timer in place so 3 bullets are created every so often.
Here's the code...
void Player::Update(float dt) {
force = force / 1.04;
UpdateSkills(dt);
float moveDirection = 0;
if(agk::GetRawMouseRightPressed()) {
if(!bombActive)
{
UseBomb();
}
}
if(bombActive) {
bombRadius += 500 * dt;
if(bombRadius > 120.0f) {
bombActive = false;
bombRadius = 0;
level->particleSystem->RemoveParticleForce("testrepulsor");
}
}
if(comboResetTimer <= 0.0f) {
combo = 1;
}
isShooting = false;
if(agk::GetRawMouseLeftState()) {
isShooting = true;
}
for(std::vector<Bullet*>::iterator it = bullets.begin(); it != bullets.end();) {
bool destroy = false;
if((*it)->GetX() < -100) {
destroy = true;
level->particleSystem->SetParticleRotation("TestParticle4", AGKVectorExt(0, 90, 0), AGKVectorExt(0, 90, 0));
(*it)->useParticles = true;
(*it)->particleBaseDir = 90.0f;
}
if((*it)->GetX() > 100) {
destroy = true;
level->particleSystem->SetParticleRotation("TestParticle4", AGKVectorExt(0, 90, 0), AGKVectorExt(0, 90, 0));
(*it)->useParticles = true;
(*it)->particleBaseDir = 180.0f;
}
if((*it)->GetY() < -61) {
destroy = true;
level->particleSystem->SetParticleRotation("TestParticle4", AGKVectorExt(90, 0, 0), AGKVectorExt(90, 0, 0));
(*it)->useParticles = true;
(*it)->particleBaseDir = 270.0;
}
if((*it)->GetY() > 61) {
destroy = true;
level->particleSystem->SetParticleRotation("TestParticle4", AGKVectorExt(90, 0, 0), AGKVectorExt(90, 0, 0));
(*it)->useParticles = true;
(*it)->particleBaseDir = 90.0f;
}
if(destroy) {
level->testEmitter2->Burst((*it)->GetPosition());
(*it)->Destroy();
it = bullets.erase(it);
}
else {
++it;
}
}
if (agk::GetRawKeyState(KEY_SPACE)) {
skill1->Use();
}
isMoving = false;
if(ControlTypeIs(KBAM))
{
if(agk::GetRawKeyState(KEY_W)) {
isMoving = true;
moveDirection = 90;
}
if(agk::GetRawKeyState(KEY_S)) {
isMoving = true;
moveDirection = 270;
}
if(agk::GetRawKeyState(KEY_A)) {
isMoving = true;
moveDirection = 180;
}
if(agk::GetRawKeyState(KEY_D)) {
isMoving = true;
moveDirection = 0;
}
if(agk::GetRawKeyState(KEY_A) && agk::GetRawKeyState(KEY_W)) {
isMoving = true;
moveDirection = 135;
}
if(agk::GetRawKeyState(KEY_A) && agk::GetRawKeyState(KEY_S)) {
isMoving = true;
moveDirection = 225;
}
if(agk::GetRawKeyState(KEY_D) && agk::GetRawKeyState(KEY_W)) {
isMoving = true;
moveDirection = 45;
}
if(agk::GetRawKeyState(KEY_D) && agk::GetRawKeyState(KEY_S)) {
isMoving = true;
moveDirection = 315;
}
if(isMoving)
{
float xx = MathHelper::LengthDirectionX(1, moveDirection);
float yy = MathHelper::LengthDirectionY(1, moveDirection);
SetVelocity((AGKVectorExt(xx, yy, 0).Normalize() * moveSpeed) + force);
}
float mx = agk::GetRawMouseX();
float my = agk::GetRawMouseY();
float md = MathHelper::PointDistance2D(500, 500, mx, my);
if(md > 80) {
agk::SetRawMousePosition(500 + MathHelper::LengthDirectionX(80, shootDirection), 500 + MathHelper::LengthDirectionY(80, shootDirection));
}
shootDirection = MathHelper::PointDirection2D(500, 500, mx, my);
shootDirection2 = shootDirection + 90;
bulletVelocity = AGKVectorExt(AGKVectorExt(mx - MathHelper::LengthDirectionX(10, shootDirection2), my - MathHelper::LengthDirectionY(10, shootDirection2), 0) - AGKVectorExt(500, 500, 0)).Normalize() * 150;
}
if(ControlTypeIs(TOUCH))
{
//agk::SetVirtualJoystickVisible(1, 0);
//if(agk::GetPointerPressed()){
//agk::SetVirtualJoystickVisible(1, 1);
//}
SetVelocity(AGKVectorExt(agk::GetVirtualJoystickX(1) * 70 , agk::GetVirtualJoystickY(1) * 70, 0));
shootDirection = MathHelper::PointDirection2D(2000, 860, 2000 + agk::GetVirtualJoystickX(2), 860 + agk::GetVirtualJoystickY(2));
shootDirection2 = shootDirection + 90;
if(agk::GetVirtualJoystickX(2) > 0 || agk::GetVirtualJoystickY(2) > 0)
{
isShooting = true;
}
bulletVelocity = AGKVectorExt(agk::GetVirtualJoystickX(2), agk::GetVirtualJoystickY(2), 0).Normalize() * 150;
}
SetVelocity(GetVelocity() / 1.1);
if(GetX() < -92) {
SetX(-92);
}
if(GetX() > 92) {
SetX(92);
}
if(GetY() < -55) {
SetY(-55);
}
if(GetY() > 55) {
SetY(55);
}
comboResetTimer -= dt;
level->particleSystem->SetParticleRotation("TestParticle4", AGKVectorExt(0, 0, 0), AGKVectorExt(0, 0, 0));
Shoot(dt);
}
void Player::Shoot(float dt) {
if(bulletTime >= 12 * dt && isShooting)
{
float angle = shootDirection - 5;
for(int i = 0; i < 3; i++)
{
bulletVelocity.x += MathHelper::LengthDirectionX(5, shootDirection2);
bulletVelocity.y += MathHelper::LengthDirectionY(5, shootDirection2);
float xx = GetX();
float yy = GetY();
if(i == 1)
{
xx = GetX() + MathHelper::LengthDirectionX(5.0f, angle);
yy = GetY() + MathHelper::LengthDirectionY(5.0f, angle);
}
Bullet *bullet;
bullet = level->Spawn<Bullet>("Bullet", AGKVectorExt(xx, yy, 0));
bullet->SetVelocity(bulletVelocity + velocity);
bullet->meshComponent->SetRotation("bullet_mesh", 0, 0, -angle);
bullets.push_back(bullet);
if(reverseFire)
{
bullet = level->Spawn<Bullet>("Bullet", AGKVectorExt(xx, yy, 0));
bullet->SetVelocity(-bulletVelocity + velocity);
bullet->meshComponent->SetRotation("bullet_mesh", 0, 0, angle);
bullets.push_back(bullet);
}
angle += 5;
}
soundComponent->PlaySound("player_shoot_sound");
bulletTime = 0;
return;
}
bulletTime += dt;
}
The bullets are stored in a vector in the player class for tracking.