Hey guys,
I have a vector of a class known has LevelBlock, each LevelBlock has an object known as DisplayObject
DisplayObject holds a sprite and other values here is the header file
#pragma once
#include "Enums.h"
#include "SFML\Graphics.hpp"
class DisplayObject
{
private:
float xPos, yPos;
sf::Sprite sprite;
DisplayName name;
std::string text;
bool textObject;
public:
DisplayObject();
~DisplayObject();
sf::Text displayText;
void SetSprite(sf::Texture texture){ sprite.setTexture(texture); }
sf::Sprite GetSprite(){ return sprite; }
void SetDisplayName(DisplayName setName){ name = setName; }
DisplayName GetDisplayName(){ return name; }
bool IsTextObject(){ return textObject; }
void SetTextObject(bool set){ textObject = set; }
void SetPosition(float xSet, float ySet);
};
Now in my level class I populate my vector of LevelBlocks to hold one block, I set the position for the sprite correctly, then I go ahead and pass a reference of the LevelBlocks DisplayObject for that block to my RenderService, so now the RenderService holds a reference to the block so it can render it, here is the code that converts my vector of LevelBlocks to vector of pointer DisplayObjects
std::vector<DisplayObject*> Level::GetLevelBlockDisplayObjects()
{
std::vector<DisplayObject*> tempBlocks;
for (auto block : blocks)
{
tempBlocks.push_back(&block.displayObject);
}
return tempBlocks;
}
void Level::Setup()
{
renderService->LevelDisplayObjects = GetLevelBlockDisplayObjects();
}
//Inside my renderService
//Display the level blocks
for (const auto& object : LevelDisplayObjects)
{
Window.draw(object->GetSprite());
}
Check my DisplayObjectSprite.png to see the values of the sprite at ""Window.draw(object->GetSprite());"" line.
Check my DisplayObjectCorrectSpriteValues.png to see the values before it goes thought my ""GetLevelBlockDisplayObjects"" function.
Also the sprite is never displayed, but I don't get any errors at all trying to render it