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
31
Which is the best way converting image from the window and then adding effects to it, and again render it to the window? I saw this technic from https://www.youtube.com/user/ThinMatrix/featured (video https://www.youtube.com/watch?v=uZlwbWqQKpc)

My idea is to convert image and resize it to the nearest available resolution and adding some effects to it  :).

32
Graphics / RenderWindow->create no instance of overloaded function
« on: September 19, 2016, 10:04:22 pm »
My code is not working...why?

sf::RenderWindow* window = game->getWindow();

window->/*error*/create(sf::VideoMode(1600, 800), game->getName(), sf::Style::Default, window_settings);

error: no instance of overloaded function "sf::RenderWindow::create" matches the argument list

33
Graphics / Re: How to get size of the scaled sprite texture
« on: September 11, 2016, 10:26:08 am »
Fixed by calling sprite.getGlobalBounds()

34
Graphics / Re: sprite.setSmooth(true) is not working for reduced texture
« on: September 11, 2016, 12:07:27 am »
It's working. I just had to put antialising to 100.

35
Graphics / Re: sprite.setSmooth(true) is not working for reduced texture
« on: September 10, 2016, 11:57:28 pm »
Enabling smooth on a sprite (or any SFML shape) applies only to its texture not the edges of the actual quad/triangles. Therefore, to enable texture smoothing for a sprite, you need to enable smooth on its texture.

As DarkRoku already mentioned, the way to "smooth" (i.e. remove aliasing) a triangle (i.e. the shape's edge) is to enable anti-aliasing.
Already did that and not working...

36
Graphics / Re: texture.setSmooth(true) is not working for reduced texture
« on: September 10, 2016, 11:55:27 pm »
If you are using a sf::Shape i think that the Anti-Aliasing have more to do with it than the texture smooth filtering.

See sf::RenderWindow class and its contex settings parameter -> Anti aliasing level option.
I already did that and it's still not working. Btw it's texture.setSmooth not sprite.setSmooth.

37
Graphics / How to get size of the scaled sprite texture
« on: September 10, 2016, 11:38:23 pm »
As title says how can i get size of the scaled sprite texture?

38
General / Returning struct from function is not working
« on: September 08, 2016, 01:04:06 am »
Returning struct from function is not working, and i don't know why. Can someone help me?
        struct Position {

                float x, y;

                Position(float position_x, float position_y) {

                        x = position_x;

                        y = position_y;

                }

        };
        Position Object::getPosition() {

                Position position(sprite.getPosition().x, sprite.getPosition().y);

                return position;
        }
        void updateGame() {

                int ball_position_main_x = 50, ball_position_main_y = 50;

                while (game_run) {

                        std::cout << Object::getObject("test")->getPosition().x;

                        Object::getObject("test")->moveRight(1);

                        sf::sleep(sf::milliseconds(10));

                }

        }

39
Graphics / Re: sprite.setSmooth(true) is not working for reduced texture
« on: September 07, 2016, 10:31:29 pm »
Edges of ball are sharp

40
Graphics / Re: sprite.setSmooth(true) is not working for reduced texture
« on: September 07, 2016, 10:28:42 pm »

41
Graphics / sprite.setSmooth(true) is not working for reduced texture
« on: September 07, 2016, 10:21:46 pm »
As title says sprite.setSmooth(true) is not working for object.getSprite()->setScale(0.1f, 0.1f);
Why? And how do i fix this? Thanks  :D

42
I don't know what you mean?

43
Not working... i tried everything  :-\. Here is rest of my code:
Game.cpp:
#include "Game.h"
#include "Graphics.h"
#include <iostream> //to remove
#include "GameObject.h"

namespace Game {

        const std::string game_name = "Game";

        bool game_opened = false;

        bool game_running = false;

        sf::Thread updategame_thread(&updateGame);

        void openGame() {

                if (game_opened) return;

                loadResources();

                startGame();

                game_opened = true;

                Graphics::openWindow();

        }

        void closeGame() {

                if (game_opened == false) return;

                stopGame();

                game_opened = false;

                Graphics::closeWindow();

        }

        void loadResources() {

                sf::Texture player_texture;

                player_texture.loadFromFile("C:/Users/User/Desktop/RANDOM ITEMS/BI logo.png");

                GameObject::GameObject gameobject("test", sf::Sprite(), player_texture); //create go

                GameObject::addGameObject(gameobject);

        }
GameObject.cpp:
#include <SFML\Graphics.hpp>
#include <string>
#include "GameObject.h"

namespace GameObject {

        std::unordered_map<std::string, GameObject> gameobjects;

        GameObject::GameObject() {

                name = "gameobject";

                sprite = sf::Sprite();

                texture = sf::Texture();

                sprite.setTexture(texture);

        }

        GameObject::GameObject(std::string gameobject_name, sf::Sprite gameobject_sprite, sf::Texture gameobject_texture) {

                name = gameobject_name;

                sprite = gameobject_sprite;

                texture = gameobject_texture;

                sprite.setTexture(texture);

        }

        void addGameObject(GameObject gameobject) {

                gameobjects[*gameobject.getName()] = gameobject;

        }

        GameObject* getGameObject(std::string gameobject_name) {

                return &gameobjects[gameobject_name];
        }

        std::string* GameObject::getName() {

                return &name;
        }

        sf::Sprite* GameObject::getSprite() {

                return &sprite;
        }

        sf::Texture* GameObject::getTexture() {

                return &texture;
        }

}
 
And Graphics.cpp:
#include <SFML\Graphics.hpp>
#include "Game.h"
#include "GameObject.h"

namespace Graphics {

        sf::RenderWindow window;

        void openWindow() {

                window.create(sf::VideoMode(800, 800), *Game::getGameName());
                window.setVerticalSyncEnabled(true);

                while (window.isOpen()) {

                        sf::Event event;

                        while (window.pollEvent(event)) {

                                switch (event.type) {

                                case sf::Event::Closed:

                                        Game::closeGame();

                                        break;
                                }

                        }

                        window.clear();

                        GameObject::GameObject* gameobject = GameObject::getGameObject("test");

                        window.draw(*gameobject->getSprite()); //and i got white box...

                        window.display();

                }

        }
 
Btw i just started with c++, i came from java. So i think that's the reason why i have problem with pointers...

44
Thank you very much!

45
Can you please tell me where is my mistake  :-\?
GameObject.cpp:
#include "GameObject.h"
#include <unordered_map>

namespace GameObject {

        std::unordered_map<std::string, GameObject> gameobjects;

        GameObject::GameObject() {

                name = "gameobject";

                sprite = sf::Sprite();

        }

        GameObject::GameObject(std::string gameobject_name, sf::Sprite gameobject_sprite, sf::Texture sprite_texture, int gameobject_position_x, int gameobject_position_y) {

                name = gameobject_name;

                sprite = gameobject_sprite;

                sprite.setTexture(sprite_texture);

                sprite.setPosition(gameobject_position_x, gameobject_position_y);

        }

        void GameObject::setName(std::string gameobject_name) {

                name = gameobject_name;

        }

        void GameObject::setSprite(sf::Sprite gameobject_sprite) {

                sprite = gameobject_sprite;

        }

        void GameObject::setTexture(sf::Texture gameobject_texture) {

                sprite.setTexture(gameobject_texture);

        }

        std::string* GameObject::getName() {

                return &name;
        }

        sf::Sprite* GameObject::getSprite() {

                return &sprite;
        }

        void addGameObject(GameObject gameobject) {

                gameobjects[*gameobject.getName()] = gameobject;

        }

        void removeGameObject(std::string gameobject_name) {

                gameobjects.erase(gameobject_name);

        }

        GameObject* getGameObject(std::string gameobject_name) {

                return &gameobjects[gameobject_name];
        }

        //std::vector<GameObject*> getGameObjects() {

        //      std::vector<GameObject*> gameobjects_c2;

        //      gameobjects_c2.reserve(gameobjects.size());

        //      for (auto gameobject : gameobjects) {

        //              gameobjects_c2.insert(gameobjects_c2.begin(), &gameobject.second);

        //      }

        //      return gameobjects_c2;
        //}

}
 
GameObject.h:
#include <SFML\Graphics.hpp>

namespace GameObject {

        class GameObject {

        private:

                std::string name;

                sf::Sprite sprite;

        public:

                GameObject();

                GameObject(std::string gameobject_name, sf::Sprite gameobject_sprite, sf::Texture sprite_texture, int gameobject_position_x, int gameobject_position_y);

                void setName(std::string gameobject_name);

                void setSprite(sf::Sprite gameobject_sprite);

                void setTexture(sf::Texture gameobject_texture);

                std::string* getName();

                sf::Sprite* getSprite();

        };

        void addGameObject(GameObject gameobject);

        void removeGameObject(std::string gameobject_name);

        GameObject* getGameObject(std::string gameobject_name);

        /*std::vector<GameObject*> getGameObjects();*/

}
 
Graphics.cpp:
#include <SFML\Graphics.hpp>
#include "Game.h"
#include "GameObject.h"
#include <iostream>

namespace Graphics {

        sf::RenderWindow window;

        void openWindow() {

                window.create(sf::VideoMode(800, 800), Game::getGameName());
                window.setVerticalSyncEnabled(true);

                while (window.isOpen()) {

                        sf::Event event;

                        while (window.pollEvent(event)) {

                                switch (event.type) {

                                case sf::Event::Closed:

                                        Game::closeGame();

                                        break;
                                }

                        }

                        window.clear();

                        GameObject::GameObject* gameobject = GameObject::getGameObject("player_gameobject");

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

                        window.display();

                        //for (i = 0; i<drawTable.size(); i++)
                        //{
                        //      m_app->Draw(*drawTable[i]); //Here is the line causing the crash !
                        //}
                        //i = 0;

                }

        }

        void closeWindow() {

                window.close();

        }

}
 
Graphics.h:
#include <SFML\Graphics.hpp>

namespace Graphics {

        void openWindow();

        void closeWindow();

}
 

Pages: 1 2 [3] 4
anything