Tag Info

New answers tagged

0

I think what you're looking for is to draw all of your tiles each frame to a sf::RenderTexture and then render that single object to the screen. The render texture is stored in an offscreen texture which is great for precomputing a complex static texture (like a level's background from multiple tiles) etc. Example: // Create a new render-window ...


0

Your problem is most likely the fact that you create copies of your blocks when adding them to your vector. That way once the original copy/block is destroyed, the texture won't be valid anymore (since there's a shallow copy happening, so even the new copies still point to the old texture, despite having their own copy). As a potential fix, change your ...


0

I am the guy who asked this question. When I asked this question I didn't knew much about sprites and textures, but then I learned quite a lot from the internet and sfml tutorials. Actually what I was doing in the program was not correct. I was storing the texture in a local scope which was getting destroyed at the end of the scope. Textures should be stored ...


0

The simplest solution is to keep textures in World class, like this: class World { public: World(); void draw(sf::RenderWindow *window); vector<Block> blocks; private: int level[12][16]; int wd; int hi; sf::Texture Texture; }; And definition: World::World() { if ...


0

I'm not sure if you're speaking of inability to keep up with FPS or UPS (Updates Per Seconds), but if machine has lower frames per second than expected you shouldn't change rate at which you're logic is being updated (UPS). Content of window is drawn depending on machine's capabilities but logic (and physics) run at constant and independent rate. In this ...


0

A quick test, just grab the logo image from the SFML site and paste it into the working directory of your project (or just somewhere simple and explicitly state that in code i.e. "C:\test\img.png") #include <vector> #include <iostream> #include <SFML/Graphics.hpp> int main() { sf::Texture texture; if ...


0

You appear to be correctly storing a texture and then setting that texture to a sprite, so I don't think the White Square problem they're referring to in the documentation applies to you in this situation as you don't have the texture being created in a local function scope etc. std::vector<T>::push_back() creates a copy of the argument and stores it ...


1

sf::Window is part of the SFML Window module but sf::RenderWindow is part of the SFML Graphics module. Hence you have to include SFML/Graphics.hpp in order to use it.


0

Your issue here is not that you are not using sf::Window::setFramerateLimit(unsigned int limit), but that you are only actually calculating your frameTime variable once, as it is really a constant. All that you have to do is change: const sf::Int64 frameTime = 1000000/FRAMES_PER_SECOND; to: sf::Int64 frameTime = 1000000/FRAMES_PER_SECOND; and that ...


0

This might not be a solution to problem , but as far as I know main game loop should not be limited using sf::Window::setFramerateLimit(unsigned int limit). Only game logic, AI, physics should be limited, events should be processed without any limitation as not to create input lag. I would suggest: sf::Clock clock; sf::Time accumulator = sf::Time::Zero; ...



Top 50 recent answers are included