Hello. Initially, I was trying to separate my main.cpp to different classes for each player for my game in SFML 3.0.0 I'm trying to build, but when trying to assign a local variable to my class the compiler gives me an error saying "Impossible to make reference to a deleted function" image showing the error description.
So, I tried using including my class name in the (public:) mode in my "Skeleton.h" (class name)
#pragma once
#include <SFML/Graphics.hpp>
#ifndef SKELETON_H
#define SKELETON_H
class Skeleton
{
public:
Skeleton(); // Constructor
void Initialize();
bool Load(const std::string& path); // Load textures or other resources
void Update(); // Update position, animations, etc.
void Draw();
private:
sf::Texture texture;
sf::Sprite sprite;
};
#endif
and it made it seem as if the problem was solved in my main.cpp
here:
int main()
{
sf::RenderWindow window(sf::VideoMode({ 600, 600 }), "CODE SFML");
window.setFramerateLimit({ 65 });
sf::Clock dtClock, fpsTimer;
std::vector<RectangleShape> bullets;
float bulletSpeed = 1.8f;
// now its time (deconstruct movement bullet
sf::Texture skeletonTexture;
sf::Sprite skeletonSprite(skeletonTexture);
Skeleton skeleton;
skeleton.Initialize();
if(!skeleton.Load("assets/player/Texture/BODY_skeleton.png")) {
skeletonSprite.setTextureRect(IntRect({ 2 * 64, 2 * 64 }, { 64, 64 }));
skeletonSprite.setPosition(Vector2f({ 35,25 }));
skeletonSprite.setScale(Vector2f({ 1,1 }));
return -1; // Exit if texture fails to load
}
However, when I run the code in the compiler, it gives me LNK2019 issues where there's an unresolved external symbol. I think it's somehow linked to the default constructors that SFML deleted for the sf::Sprite but I would like to hear your guys thoughts on it. Please, if possible, provide me the answer with an example.
my Skeleton.cpp
#include "Skeleton.h"
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf;
void Skeleton::Initialize()
{
}
bool Skeleton::Load(const std::string& path)
{
if (!texture.loadFromFile("assets / player / Texture / BODY_skeleton.png", false, sf::IntRect({2 * 64, 2 * 64}, {64, 64})))
{
std::cerr << "Error: Could not load texture!" << std::endl;
sprite.setTexture(texture);
return true;
}
}
void Skeleton::Update()
{
}
void Skeleton::Draw()
{
}