Morning,
I am struggling with a particular issue when entering a cave and I am trying to swap over to a different sprite sheet for the environmental textures in the cave. The rest of the game is working as intended, but when entering the cave I am still getting texture from the old sheet.
I imagine this is something simple but I really struggle with SFML-related issues. Hoping someone can point me in the right direction. Code below:
This is near the beginning of main just outside the game loop. Pretty standard I suppose but here it is:
transnavcontrol(inewmap);
inewmap = -1;
sf::Texture envtexture;
envtexture.loadFromFile(envss); ////This will have the overworld map as I start from there
This piece looks for a new map and IS triggering and also the variable envss does have the correct sprite sheet (new one).
inewmap = coll.getnewmap(envarrayt, linkx, linky, camoffsetx, camoffsety, stride, mapsizex, envarraym, width, height);
if (inewmap != -1) { ////new maps are numbered from 0 - 15
transnavcontrol(inewmap); //// finds toon placement, 'camera' adjustment, new sheet etc
inewmap = -1;
sf::Texture envtexture;
envtexture.loadFromFile(envss); ////This variable DOES have the location of the new cave sheet
if (!envtexture.loadFromFile(envss)) {
cout << "Could not load new map sprite sheet" << endl; ////error is not triggering
}
This next piece might make some of you folks that understand SFML better than I do a conniption - apologies. This does the environmental drawing. This is a simplified version as I currently do not understand or use vertex arrays and am detecting vertically and horizontally iterated tiles and am not drawing them - saves about 30% of draw calls. envarrayx & y are arrays of x/y coordinates, envarrayi is a array of which tiles need to be widened to cover gaps where the next isn't being drawn. This is all in nested while loops but they should be good.
environment env;
sf::Sprite spriteenv;
envlocx = env.elocx(tilepositionstartx);
envlocy = env.elocy(tilepositionstarty);
cout << envss << endl;
spriteenv.setTexture(envtexture);
spriteenv.setPosition(envlocx - camoffsetx, envlocy - camoffsety);
spriteenv.setTextureRect(sf::IntRect(envarrayx[(tilepositionstarty * mapsizex) + tilepositionstartx], envarrayy[(tilepositionstarty * mapsizex) + tilepositionstartx], (48 * envarrayi[(tilepositionstarty * mapsizex) + tilepositionstartx]), 48));
window.draw(spriteenv);
Please let me know if this is something dumb (I am expecting it is) or if you need some more details
thanks