Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Unable to swap sprite sheets during transition to a new area  (Read 1345 times)

0 Members and 1 Guest are viewing this topic.

nimn

  • Newbie
  • *
  • Posts: 13
    • View Profile
Unable to swap sprite sheets during transition to a new area
« on: January 17, 2017, 04:27:23 am »
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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Unable to swap sprite sheets during transition to a new area
« Reply #1 on: January 17, 2017, 10:18:19 am »
Personally I suggest to use some sort of a resource holder and then you can load both textures at the beginning and just set a different texture om the sprites when drawing.

http://www.bromeon.ch/libraries/thor/tutorials/v2.0/resources.html
https://github.com/SFML/SFML-Game-Development-Book/tree/master/02_Resources/Include/Book
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything