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 - Putarda

Pages: 1 [2] 3 4
16
Graphics / Re: Rendering object through virtual function
« on: October 31, 2016, 08:54:33 pm »
Damn, I can't believe how much time I spent researching, while I can just put Drawable...
Anyway thanks  ;D

17
Graphics / Re: Rendering object through virtual function
« on: October 30, 2016, 04:19:55 pm »
The point of writing new Rectangle class is because I can't store sf::RectangleShape in map<std::string, Object*>. Any better solution than mine?

I wrote Object class because I needed more types of shapes in std::map. I found a way by writing base class Object and having derived classes (like types: Rectangle, Circle). Spent so much time researching for that code, I forgot the point of it.

18
Graphics / Rendering object through virtual function
« on: October 30, 2016, 01:14:40 pm »
Is this good idea? This is the only way I found how to render rectangleshape from derived class.

Object (base class) and Rectangle (derived class)
        class Object {

        private:

                std::string name;

        public:

                Object() = default;

                Object(std::string object_name) : name(object_name) {}

                virtual void draw(sf::RenderWindow* renderwindow) = 0;

                virtual void setPosition(float, float) = 0;

                virtual void setRotation(float) = 0;

                const std::string* getName() {
                       
                        return &name;
                }

                const virtual Position getPosition() = 0;

                const virtual Rotation getRotation() = 0;

        };

        class Rectangle : public Object {

        private:

                sf::RectangleShape rectangleshape;

        public:

                Rectangle() = default;

                Rectangle(std::string name, float width, float height) : rectangleshape(sf::Vector2f(width, height)), Object(name) {}

                void draw(sf::RenderWindow* renderwindow) {

                        renderwindow->draw(rectangleshape); //is this good idea, will this slow my Engine?

                }

                void setPosition(float position_x, float position_y) {

                        rectangleshape.setPosition(position_x, position_y);

                }

                void setRotation(float angle) {

                        rectangleshape.setRotation(angle);

                }

                sf::RectangleShape* getRectangleShape() {

                        return &rectangleshape;
                }

                const Position getPosition() {

                        return Position(rectangleshape.getPosition().x, rectangleshape.getPosition().y);
                }

                const Rotation getRotation() {

                        return Rotation(rectangleshape.getRotation());
                }

        };

And here is render:
        void Engine::startDraw() {

                sf::View view;

                view.setSize(1920, 1080);
                view.setCenter(view.getSize().x / 2, view.getSize().y / 2);

                view = getLetterboxView(view, window.getSize().x, window.getSize().y);

                while (isOpen()) {
                       
                        sf::Event event;

                        while (window.pollEvent(event))
                        {

                                switch (event.type) {

                                case sf::Event::Closed:

                                        run = STOP;

                                        window.close();

                                        return;
                                case sf::Event::Resized:

                                        view = getLetterboxView(view, event.size.width, event.size.height);

                                        break;

                                }

                        }

                        window.clear(sf::Color::Black);
                        window.setView(view);

                        getObject("rect")->draw(&window); //good idea?

                        window.display();

                }

        }

If not, can someone give me a better way  :)? Thanks.

19
So basicly I have few question that I need to know to continue my Engine  ;D.

1. Does opengl render off the screen shapes (sf::Rectangle, sprite...). For example if rectangle position is at 1281 but screen is 1280, will it be rendered?
2. Is it true that 2D games screen is just a plane in 3D space with texture on it? Like this:
3. When I'm making my infinite runner, is it better to move my camera (sf::view) and generate map when it needs to appear or to just move all sprites at the opposite running direction and generating a map when it needs to appear?
4. Similar as third question, when I make my adventure game. Do I need to load my whole scene/map at the beggining, or to generate it when it needs to appear?

5. And one more important question. At the beggining of the game, should I load all objects, entities and particles to resource map. And when I need for example to spawn enemy, I just take that entity type from resource map and duplicate it in my other map called screen map which will render it and share it. Is that good mechanism for my Engine?

I'm making my first engine, and I'm looking it to be good as possible. I hope someone can answer my questions. Thanks.

20
Window / How to properly set icon to window?
« on: October 08, 2016, 12:38:46 am »
I searched on the internet for the answer, and all I found were topics older than 8 years. My question is what is the best and properly way to set icon to the render window? And also to .exe.

21
Graphics / Re: Render function freezes before while is Open
« on: October 05, 2016, 12:27:29 am »
Can someone help me please :/?

22
Graphics / Re: Render function freezes before while is Open
« on: October 03, 2016, 12:36:08 am »
And my render and update functions are in separated threads. Render function is in the main thread ofcourse.

23
Graphics / Re: Render function freezes before while is Open
« on: October 03, 2016, 12:34:17 am »
Main:
int main() {

        Game::Game* game = new Game::Game("L Speed");

        game->initialize();

        delete game;

        return 0;
}
Game:
        Game::Game(std::string game_name) {

                setName(game_name);

                loadResources();

                Window::createWindow(this, &window);

        }

        void Game::initialize() {

                sf::Thread run_thread(&Game::startRun, this);

                run_thread.launch();

                startDraw();

        }

        void Game::addObject(Object::Object object) {

                objects[*object.getName()] = object;

        }

        void Game::setName(std::string game_name) {

                name = game_name;

        }

        void Game::setRun(Game_Run game_run) {

                run = game_run;

        }

        void Game::loadResources() {

                Object::Object object("ball", "ball.png");

                auto object_size = object.getSprite()->getTexture()->getSize();
                object.getSprite()->setScale(float(150) / object_size.x, float(150) / object_size.y);

                Game::addObject(object);

        }

        void Game::startRun() {

                setRun(START);

                Object::Object* object = Game::getObject("ball");

                while (isOpen()) {

                        object->move(2, 2);

                        sf::sleep(sf::milliseconds(17));

                }

        }

        void Game::startDraw() {

                window.setActive(true);
//freeze problem (white screen). until I add std::cout
                while (isOpen()) {
                       
                        sf::Event event;

                        while (window.pollEvent(event))
                        {

                                switch (event.type) {

                                case sf::Event::Closed:

                                        setRun(STOP);

                                        window.close();

                                        return;

                                }

                        }

                        window.clear(sf::Color::Blue);

                        for (auto object : getObjects()) {

                                window.draw(*object->getSprite());

                        }

                        window.display();

                }

        }
Window:
        void Window::createWindow(Game::Game* game, sf::RenderWindow* game_window) {

                sf::ContextSettings window_settings;

                window_settings.antialiasingLevel = 16;

                game_window->create(sf::VideoMode(1920, 1080), *game->getName(), sf::Style::Fullscreen, window_settings);

                game_window->setVerticalSyncEnabled(true);

                game_window->setActive(false);

        }

24
Graphics / Re: Render function freezes before while is Open
« on: October 02, 2016, 07:44:22 pm »
Because of this
        Game::Game(std::string game_name) {

                setName(game_name);

                loadResources();

                Window::createWindow(this, &window);

        }

        void Game::initialize() {

                sf::Thread run_thread(&Game::startRun, this);

                run_thread.launch();

                startDraw();

        }

25
Graphics / Render function freezes before while is Open
« on: October 02, 2016, 03:11:46 pm »
In my function Game::startDraw(), before draw starts I call window.setActive(true), after that rest of the code is freezed. But, if there is std::cout, freeze is declined. Why??

Working code:
        void Game::startDraw() {

                window.setActive(true);

                std::cout << "Don't freeze!";

                while (isOpen()) {
                       
                        sf::Event event;

                        while (window.pollEvent(event))
                        {

                                switch (event.type) {

                                case sf::Event::Closed:

                                        setRun(STOP);

                                        window.close();

                                        return;

                                }

                        }

                        window.clear(sf::Color::Blue);

                        for (auto object : getObjects()) {

                                window.draw(*object->getSprite());

                        }

                        window.display();

                }

        }

I'm not sure but I think problem is caused by window.setActive().
Window create function:
        void Window::createWindow(Game::Game* game, sf::RenderWindow* game_window) {

                sf::ContextSettings window_settings;

                window_settings.antialiasingLevel = 16;

                game_window->create(sf::VideoMode(1920, 1080), *game->getName(), sf::Style::Fullscreen, window_settings);

                game_window->setVerticalSyncEnabled(true);

                game_window->setActive(false);

        }

26
Window / Re: Aspect ratio confusion
« on: October 02, 2016, 02:46:02 pm »
And it's not working.... nothing changes, there is not letterbox.

27
Window / Re: Aspect ratio confusion
« on: October 02, 2016, 11:31:29 am »
Yes, just like that :D. Thanks.

28
Window / Re: Aspect ratio confusion
« on: October 01, 2016, 01:07:43 pm »
Thank you for your answer. But I was more thinking about this

29
Window / Aspect ratio confusion
« on: September 28, 2016, 12:50:04 am »
Currently i'm at the point where I don't know where to start. I want to make game where view will be equal on different screen resolutions. I don't know how and where to start and how other games do it. How do i calculate that. For good explanation i will be so thank thankful  :).

Btw here is my window code and render code:

Window.cpp:
        void Window::createWindow(Game::Game* game, sf::RenderWindow* game_window) {

                sf::ContextSettings window_settings;

                window_settings.antialiasingLevel = 16;

                game_window->create(sf::VideoMode::getDesktopMode(), *game->getName(), sf::Style::Fullscreen, window_settings);

                game_window->setVerticalSyncEnabled(true);
               
                game_window->setActive(false);

        }

Game.cpp (render code):
        void Game::startDraw() {

                window.setActive(true);

                sf::RenderTexture screen_layer_rendertexture;

                sf::Sprite screen_layer_sprite;

                if (!screen_layer_rendertexture.create(1920, 1080)) {

                        Main::printError("Can't create the texture.");

                        exit(-1);

                }

                screen_layer_rendertexture.setSmooth(true);

                screen_layer_sprite.setTexture(screen_layer_rendertexture.getTexture());

                while (isOpen()) {

                        sf::Event event;

                        while (window.pollEvent(event))
                        {

                                switch (event.type) {

                                case sf::Event::Closed:

                                        setRun(STOP);

                                        window.close();

                                        return;
                                }

                        }

                        screen_layer_rendertexture.clear(sf::Color::White);

                        for (auto object : getObjects()) {

                                screen_layer_rendertexture.draw(*object->getSprite());

                        }

                        screen_layer_rendertexture.display();

                        window.clear(sf::Color::Red);

                        window.draw(screen_layer_sprite);

                        window.display();

                }

        }

30
Thank you!

Pages: 1 [2] 3 4
anything