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";
}
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";
}