Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - alaninho_08

Pages: [1]
1
Graphics / Re: Problem with initialization of my variable to its class
« on: January 17, 2025, 05:19:28 pm »
Hello,
thank you for your response. It looks like I don't have a problem with my sf::sprite,but as I run my code, I only get a white square, maybe "the white square problem", but I don't see no problem with my code.

main.cpp:
Skeleton skeleton;
Orc orc;
sf::Texture texture;   
sf::Texture texture2;
sf::Sprite sprite(texture);
sf::Sprite sprite2(texture2);


if (skeleton.Load("assets/player/Texture/BODY_skeleton.png")) {
    sprite.setTexture(texture);
    sprite.setPosition(Vector2f({ 35, 25 }));
    sprite.setScale(Vector2f({ 1, 1 }));
    cout << "BODY_skeleton.png loaded successfully.\n";
}
else {
    cout << "Failed to load BODY_skeleton.png.\n";
}


if (orc.Load("assets/player/Texture/Orc.png")) {
    sprite2.setTexture(texture2);
    sprite2.setScale(Vector2f({ 2, 2 }));
    sprite2.setPosition(Vector2f({ 500, 425 }));
    cout << "Orc.png loaded successfully.\n";
}
else {
    cout << "Failed to load Orc.png.\n";
}

skeleton class: Skeleton skeleton;
Orc orc;
sf::Texture texture;   
sf::Texture texture2;
sf::Sprite sprite(texture);
sf::Sprite sprite2(texture2);


if (skeleton.Load("assets/player/Texture/BODY_skeleton.png")) {
    sprite.setTexture(texture);
    sprite.setPosition(Vector2f({ 35, 25 }));
    sprite.setScale(Vector2f({ 1, 1 }));
    cout << "BODY_skeleton.png loaded successfully.\n";
}
else {
    cout << "Failed to load BODY_skeleton.png.\n";
}


if (orc.Load("assets/player/Texture/Orc.png")) {
    sprite2.setTexture(texture2);
    sprite2.setScale(Vector2f({ 2, 2 }));
    sprite2.setPosition(Vector2f({ 500, 425 }));
    cout << "Orc.png loaded successfully.\n";
}
else {
    cout << "Failed to load Orc.png.\n";
}

2
Graphics / Problem with initialization of my variable to its class
« on: January 17, 2025, 06:03:54 am »
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()
{
}

Pages: [1]