#No default constructor in SFML 3.02
8 messages · Page 1 of 1 (latest)
When your question is answered use !solved or the button below to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
Here is my source file
#include "RenderSystem.h"
#include <SFML/Graphics.hpp> // didn't need to do this because it's included from the header file
RenderSystem::RenderSystem(sf::RenderWindow& window)
:main_window(window)
tileSprite(tileTexture)
{
}
void RenderSystem::loadResources() {
tileTexture.loadFromFile("C:/Users/kaleb/Downloads/grass.jpg"); // tileTexture is a default datatype that contains images
tileSprite.setTexture(tileTexture);
}
void RenderSystem::draw() {
main_window.clear(sf::Color(20, 20, 20));
// Example: draw a single tile
tileSprite.setPosition({100, 100});
main_window.draw(tileSprite);
main_window.display();
}
And header
#pragma once
#include <SFML/Graphics.hpp>
class RenderSystem { // class is a user-defined data type that serves as a blueprint or template for creating objects
public:
RenderSystem(sf::RenderWindow& window); // << constructor, we pass in a window (it's going to be the main window from main)
void loadResources(); // this one loads textures from disk, and prepares sprites to be drawn
void draw(); // this one clears screen, draws sprites, and displays the final frame
private:
sf::RenderWindow& main_window; // this is an alias (a "fake" name for the passed in window that we'll use here only)
sf::Texture tileTexture; // default-constructible; Stores image data loaded from a file like grass.png
sf::Sprite tileSprite; // this references a texture, has position, scale, and rotation. It will be drawn
};
RenderSystem::RenderSystem(sf::RenderWindow& window) :
main_window(window),
tileSprite(tileTexture)
{}
```You're missing a comma after `main_window` in `RenderSystem()`
Thank you so much!
@wraith wave Has your question been resolved? If so, type !solved :)
!solved