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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - nimn

Pages: [1]
1
Graphics / Re: .setColor and vertex arrays?
« on: January 03, 2018, 01:13:00 pm »
ok sorry - follow up question...

So the tinting works pretty well in manipulating colors, however, I can't get white with a tint as far as I see.
Is white possible with a colored (non-white) texture? any tricks?

thanks again

2
Graphics / Re: .setColor and vertex arrays?
« on: January 03, 2018, 12:45:20 pm »
got it working - thanks for the help!

3
Graphics / .setColor and vertex arrays?
« on: December 27, 2017, 08:31:52 am »
hello,

quick question on vertex arrays and transforms.
I see in sprites there is a set color function allowing tinting as well as opacity changes
However, I do not see it, or how it would be implemented with vertex arrays

I've been all over the tutorials, docs and google - any help?

4
Audio / Re: Music hangs on setPlayingOffset
« on: December 01, 2017, 07:08:24 am »
Disregard - I got it working last night after building it out with some more planning
Not sure what the problem was, no changes in paradigm but is working currently

thanks

5
Audio / Re: Music hangs on setPlayingOffset
« on: November 28, 2017, 09:03:34 pm »
howdy

SFML 2.4.2
Windows 7 64 sp1
Visual Studio Community '17

additionally i should make it clear that the game does not hang, it seems to progress at regular speed, but the sound is delayed a bit before playing from defined location. I've tried defining with millisecond & seconds. I take it this is not expected - not just closing and opening the source? The source is 1396kB and wav format 1:29s long. I think I have pretty well emulated known-working code provided on youtube videos and such but am getting this hang on different files and defining with SFML sound and music.

Please let me know if more code would help


6
Audio / Music hangs on setPlayingOffset
« on: November 28, 2017, 05:14:29 am »
morning,

I have sound and music playing, my problem is that when setPlayingOffset is called it hangs for about .25 seconds and then plays from that location. The location it plays from is good, but i get about a quarter second of silence. I am using it as music in a small array for actual music, rain and anything else that may arise.

I've done some googling but cant find anything... any ideas?

The Below are c+p'ed from multiple places - hope its coherent
sf::Music music[3];

void Soundtrack::musicreconciliation(ENV &env, int i) {
        if (env.musicbuffername[i] == "4 Overworld") {
                env.music[i].setPlayingOffset(sf::Time(sf::milliseconds(7000)));
                env.musicbufferduration[i] = 4250; //frames to be expired before calling this func again
        }
        else if (env.musicbuffername[i] == "rain") {
                env.music[i].setPlayingOffset(sf::Time(sf::milliseconds(2000)));
                env.musicbufferduration[i] = 120;
        }
}

 

7
Audio / Re: Compiler errors on music & sound
« on: July 02, 2017, 02:37:24 am »
Thanks dude
I went back over the sfml setup tut and found that I had 3/5 of the modules or whatever linked
Its working great now thanks again

8
Audio / Compiler errors on music & sound
« on: July 01, 2017, 07:17:03 am »
Hello - I am getting compiler errors when including any sound or music class
Seem to be Linker errors? not sure - but it all goes sideways once I use either "sf::Music music" or sf::Sound sound". I have #include <SFML/Audio.hpp> and am not sure how to address these... thanks!

For context, I have sprites, vertex arrays, and a few other bits working great- only audio refuses to compile

Errors:
1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Music::Music(void)" (__imp_??0Music@sf@@QAE@XZ) referenced in function "public: void __thiscall Loop::gameloop(struct ENV &,struct INP &,struct LN &,struct UI &)" (?gameloop@Loop@@QAEXAAUENV@@AAUINP@@AAULN@@AAUUI@@@Z)

1>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::Music::~Music(void)" (__imp_??1Music@sf@@UAE@XZ) referenced in function "public: void __thiscall Loop::gameloop(struct ENV &,struct INP &,struct LN &,struct UI &)" (?gameloop@Loop@@QAEXAAUENV@@AAUINP@@AAULN@@AAUUI@@@Z)

9
Graphics / using .h with the vertex array tutorial
« on: March 04, 2017, 01:30:32 am »
howdy,

Executive Summary:
I'm getting an error when moving class definition to a separate .h file -
(no instance of overloaded function "sf::RenderWindow::draw" matches the argument list)   

Narrative:
Having a dumb issues that I'm too dumb to figure out.
I have a pretty decent game going (avatar related) that is entirely sprite based.
I have been needing a major upgrade to vertex arrays   
Just trying to adapt the vertex array tutorial the game and will rebuild around it.
Trying to move class definitions (interpret loosely - terminology?) to a .h file. First step in adaptation...
heres the error: (no instance of overloaded function "sf::RenderWindow::draw" matches the argument list)   

and the .h:

class TileMap {
public:
        bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height);

private:
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
};

class loop {
        int main();
};
 

and the .cpp (spoiler alert - its the tutorial):

        bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height) {
                sf::VertexArray m_vertices;
                sf::Texture m_tileset;
                // load the tileset texture
                if (!m_tileset.loadFromFile(tileset))
                        return false;

                // resize the vertex array to fit the level size
                m_vertices.setPrimitiveType(sf::Quads);
                m_vertices.resize(width * height * 4);

                // populate the vertex array, with one quad per tile
                for (unsigned int i = 0; i < width; ++i)
                        for (unsigned int j = 0; j < height; ++j)
                        {
                                // get the current tile number
                                int tileNumber = tiles[i + j * width];

                                // find its position in the tileset texture
                                int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
                                int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);

                                // get a pointer to the current tile's quad
                                sf::Vertex* quad = &m_vertices[(i + j * width) * 4];

                                // define its 4 corners
                                quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                                quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                                quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                                quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);

                                // define its 4 texture coordinates
                                quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                                quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                                quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                                quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
                        }

                return true;
        }

void draw(sf::RenderTarget& target, sf::RenderStates states) {
        sf::VertexArray m_vertices;
        sf::Texture m_tileset;

                // apply the tileset texture
                states.texture = &m_tileset;

                // draw the vertex array
                target.draw(m_vertices, states);
        }


int main() {
        // create the window
        sf::RenderWindow window(sf::VideoMode(512, 256), "Tilemap");

        // define the level with an array of tile indices
        const int level[] =
        {
                0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
                1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3,
                0, 1, 0, 0, 2, 0, 3, 3, 3, 0, 1, 1, 1, 0, 0, 0,
                0, 1, 1, 0, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2, 0, 0,
                0, 0, 1, 0, 3, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0,
                2, 0, 1, 0, 3, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1,
                0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1,
        };

        // create the tilemap from the level definition
        TileMap map;
        if (!map.load("tileset.png", sf::Vector2u(32, 32), level, 16, 8))
                return -1;

        // run the main loop
        while (window.isOpen())
        {
                // handle events
                sf::Event event;
                while (window.pollEvent(event)) {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                // draw the map
                window.clear();
                window.draw(map);
                window.display();
        }

        return 0;
}
 




10
Graphics / 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

11
Graphics / Re: Efficient environment sprites?
« on: November 21, 2016, 12:07:49 am »
well that was a dumb mistake - but wow what a difference
Just needed a new, unique texture object (terminology?) and pull the texture definition out of the gameloop.

Got it working! as high as 6000fps!
thanks a bunch for all the help!

12
Graphics / Re: Efficient environment sprites?
« on: November 19, 2016, 10:56:11 pm »
thanks for the help

I see where your going, but the window.clear() is nuking the window and the assets only show up for a single frame unless they move. How would I get them drawn, or keep them from being cleared if they are unchanged?

thanks thanks!

13
Graphics / Efficient environment sprites?
« on: November 19, 2016, 09:53:15 pm »
Howdy, I am new to SFML and C++ to some degree as well.
My issue is that when I display my character sprite and a large background sprite I get a massive drop in frame rate. My window is only 512 x 448 and I am aiming for 60fps, but only getting 18-19 with a monolithic background sprite. I imagine that this will only get worse as I add bad dudes and such. I tried toying around with leaving the background sprite out of the loop and adding a function to redraw the background directly over just where the character was and removing the clear.window, but there seems like a much easier way should be out there but after a lot of googling I wasn't able to find it or not skillful enough to recognize/implement it.

Any help would be much appreciated

int main() {
        setup();
        sf::RenderWindow window(sf::VideoMode(512, 448), "Zelda");
        window.setFramerateLimit(60);
        sf::Clock clock;

       

                while (window.isOpen()) {
                        sf::Event event;
                        while (window.pollEvent(event)) {
                                switch (event.type) {
                                case sf::Event::Closed:
                                        window.close();
                                        break;
                                }
                        }

                        window.clear();
                        input();
                        environmentcontrol();     //supplies sprite name, coords on spritesheet etc
                       
                        ///////Environment//////
                        if (spriteenv != "null") {
                                sf::Texture texture;
                                if (!texture.loadFromFile(spriteenv)) {
                                        cout << "Didnt Load Sprite" << endl;
                                }
                                sf::Sprite sprite(texture);
                                sprite.setPosition(envx, envy);
                                sprite.setTextureRect(sf::IntRect(envx1, envy1, envx2, envy2));
                                window.draw(sprite);
                        }
                        spritecontrol();     //supplies character sprite file name, sheet location and window position

                        ////////SPRITE 1////////
                        if (sprite1 != "null") {
                                sf::Texture texture;
                                if (!texture.loadFromFile(sprite1)) {
                                        cout << "Didnt Load Sprite" << endl;
                                }
                                sf::Sprite sprite(texture);
                                sprite.setPosition(sp1x, sp1y);
                                sprite.setTextureRect(sf::IntRect(sp1x1, sp1y1, sp1x2, sp1y2));
                                sprite.setColor(sf::Color(255, 255, 255, 255));
                                window.draw(sprite);
                        }
                        sf::Time time = clock.getElapsedTime();
                        cout << 1.0 / time.asSeconds() << endl;
                        clock.restart().asSeconds();
                        window.display();
                }
        }
 

Pages: [1]
anything