So I'm getting a stange error when I'm creating a array from something I call "Obstacle", the problem I'm having is when I'm trying to load the array(sprites) they are all turning white. Now to the strange everything works perfectly when I'm not having the array (only loading one object).
I think that I'm loading the array too many times so that everything get overwriten.
I'm not going to post the Object and the Obstacle code tho I known thats right beacuse it works when I'm creating only one obejct in gameHandler.
gameHandler.h(creating the objects here and calling to load the sprites)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#pragma once
#include "Player.h"
#include "Obstacle.h"
#include "Background.h"
class gameHandler :public sf::Drawable
{
private:
staticconstint CAP = 3;
Player player = ("img/playerSheet.png");
Obstacle obstacles[CAP];
//Obstacle obstacles = ("img/obstacle.png");
Background bg = ("img/cloud.png");
void draw(sf::RenderTarget &target, sf::RenderStates states)const;
gameHandler.cpp
calling for the constructor to load the image
1 2 3 4 5 6 7
gameHandler::gameHandler()
{
for (int i = 0; i < this->CAP; i++)
{
this->obstacles[i] = Obstacle("img/obstacle.png");
}
}
This is a common problem usually it means you have destroyed the texture.
Sprites keep a pointer to the texture. If the texture gets destroyed you get a white square.
At a guess, your Obstacle class has inadequate copy constructor and copy assignment implementation. You've decided that code is irrelevant because it works with a single object, though these things never come into play with only one object.