What I'm doing is trying to get the filename of the sprite for use in a sprite sheet for a level builder. Something isn't working the way I think it should be working...
I'm using SFML 1.6, Windows 7, Visual Studio 2010 express. I've recompiled SFML for use with 2010.
The user creates a new level, and then creates a new room in that level. Then when a new room is created, they can create new tile layers (background, foreground, etc). When they do this, they specify the image file they want to use for that layer. I can get the filenames just fine. However, there are two problems. First, here is the new layer creation code:
void Room::AddNewLayer(std::string spriteFileToUse, int position, float scaleModifier)
{
tileLayers.push_back(LevelLayer(spriteFileToUse, width, height, scaleModifier));
}
the tileLayers variable is a std::vector. It's size is 0 to begin with and right now I'm just pushing them to the back of the vector to try and get something working.
Here is the LevelLayer constructor being used:
LevelLayer::LevelLayer(std::string setSpriteFile, int setWidth, int setHeight, float setScaleModifier)
{
spriteFile = setSpriteFile;
width = setWidth;
height = setHeight;
visible = true;
halfVisible = false;
scaleModifier = setScaleModifier;
tile.resize(width);
for(unsigned int i = 0; i < tile.size(); i++)
{
tile[i].resize(height);
}
spriteImage.LoadFromFile(spriteFile);
spriteSheet.SetImage(spriteImage);
}
Using the AddNewLayer function as shown does not produce an image in the tile selection window. However, if I change it to:
void Room::AddNewLayer(std::string spriteFileToUse, int position, float scaleModifier)
{
tileLayers.push_back(LevelLayer(spriteFileToUse, width, height, scaleModifier));
tileLayers[tileLayers.size() - 1].ChangeSpriteSheet(spriteFileToUse);
}
The inclusion of the second line causes the sprite to show up on the screen. Here is ChangeSpriteSheet function:
void LevelLayer::ChangeSpriteSheet(std::string newSpriteFile)
{
spriteFile = newSpriteFile;
spriteImage.LoadFromFile(newSpriteFile);
spriteSheet.SetImage(spriteImage);
}
It does the same thing as far as generating the sprite goes as the constructor but this causes it to show up. However, if another new layer is added, then the previous sprite fails to show up. The newest layer added is the only one that has it's image show up if you cycle through the layers.
This is the rendering code for getting the sprite to show up in the tile selection window (not an sf::Window):
void Editor::DrawSpriteWindow()
{
if(currentRoom != NULL && currentRoom->GetNumberOfLayers() > 0)
{
sf::Sprite temp = currentRoom->GetLayerSpriteSheet(currentLayer);
temp.SetPosition(spriteWindow.GetX(), spriteWindow.GetY());
app->Draw(temp);
}
}
I've got to be missing something but I can't see where it's going wrong.