I’m making a 2d top down shooter game and I was working on shooting bullets. Im using a vector for the bullet in my player class: std::vector b; And I have coded a shoot function which shoots the bullet and deletes it if it is out of the screen:
void Player::shoot(float timer)
{
//Getting Key Press
if (Keyboard::isKeyPressed(Keyboard::Space))
{
space = true;
}
else
{
space = false;
}
Bullet b1;
b.push_back(Bullet(b1));
if (space)
{
for (int i = 0; i < b.size(); i++)
{
b[i].setPos(pos);
}
}
else
{
for (int i = 0; i < b.size(); i++)
{
b[i].update(true);
if (b[i].getPos().y < 0.0f)
{
b.erase(b.begin() + i);
i--;
}
}
}
}
But I have encountered an error: Error C2280 'Bullet &Bullet::operator =(const Bullet &)': attempting to reference a deleted function
I don’t understand why this is happening can someone explain? Here is the bullet class Header:
#pragma once
#include <SFML/Graphics.hpp>
using namespace sf;
class Bullet
{
private:
Texture t;
Sprite bullet;
Vector2f pos;
public:
Bullet();
~Bullet();
void setPos(Vector2f pos);
void move(bool up);
Sprite getSprite();
Vector2f getPos();
};
Cpp file: #include "stdafx.h" #include "Bullet.h"
Bullet::Bullet()
{
//Setting Texture
t.loadFromFile("Graphics/bullet.png");
bullet.setTexture(t);
}
Bullet::~Bullet()
{
}
void Bullet::setPos(Vector2f pos)
{
//Setting Position
this->pos = pos;
bullet.setPosition(this->pos);
}
void Bullet::move(bool up)
{
if (up)
{
bullet.move(0.0f, -10.0f);
}
else
{
//TODO
}
}
Sprite Bullet::getSprite()
{
return bullet;
}
Vector2f Bullet::getPos()
{
return pos;
}