I have a certain image on res/player.png. I open the image with an Image Viewer, and I get the very image.
Now, I have this class, which in the end, with a ::draw() method draws it. (note that Player is an sf::Sprite).
#include "Player.hpp"
using namespace std;
Player::Player(Game *_game, Tilemap *_map)
{
game = _game;
map = _map;
/* Prepare debug label */
debugText.setFont(game->arialFont);
debugText.setCharacterSize(12);
debugText.setPosition(2, 14);
debugText.setColor(sf::Color::Red);
/* Load image */
sf::Texture texture;
if (!texture.loadFromFile("res/player.png")) {
printf("Error loading player image.\n");
}
width = 32;
height = 32;
x = 20;
y = 20;
vx = 0.f;
vy = 0.f;
setTexture(texture);
}
void Player::update()
{
debugText.setString("");
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
vx = 3;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
vx = -3;
}
/* Jumpity jumpy jump */
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
if (map->raw[(int) floor(floor(y + height + 0.5) / 8)][(int) floor(x / 8)]) {
vy = -6;
}
}
if (!map->raw[(int) floor((y + height + 1) / 8)][(int) (floor(x / 8))]) {
vy += 0.2;
}
if (vx > 0) {
for (int i = 0; i < floor(vx); i++) {
if (!map->raw[(int) floor(y / 8)][(int) floor((x + width) / 8)])
x++;
else
break;
}
} else if (vx < 0) {
for (int i = 0; i < floor(-vx); i++) {
if (!map->raw[(int) floor(y / 8)][(int) (floor((x - 1) / 8))])
x--;
else
break;
}
}
if (vy > 0) {
for (int i = 0; i < floor(vy); i++) {
if (y + height - floor(y + height) == 0.5) {
system("clear");
printf("\n\n\n\n*******\n****************************\n*************** HERE\n\n");
y + 0.001;
}
if (!map->raw[(int) floor(floor(y + height + 0.5) / 8)][(int) floor(x / 8)] &&
!map->raw[(int) floor(floor(y + height + 0.5) / 8)][(int) floor((x + width - 1) / 8)])
y++;
else
break;
}
} else if (vy < 0) {
y += vy;
}
//printf("%lf, %lf\n", y + height, floor(y + height + 0.5));
/* Apply friction */
if (vx > 0) vx -= 0.1;
if (vx < 0) vx += 0.1;
if (abs(vx) < 0.15) vx = 0;
setPosition(x, y);
}
void Player::draw() {
game->window.draw(*this);
game->window.draw(debugText);
}
And the image I get on the screen when playing the Player is a white square (32 * 32).
Any ideas on why this might be happening? Thanks. I tried renaming the image, making the project countless times.