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.


Topics - Putarda

Pages: 1 [2]
16
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  :).

17
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

18
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?

19
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));

                }

        }

20
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

21
Graphics / window.draw(*gameobject->getSprite()) texture is white, why?
« on: August 24, 2016, 03:28:04 pm »
Hello, so i'm messing with basic sfml engine about 1 week and i'm tired of it. Can anyone just help me to finish it? I just need one small step to finish it. So here is my problem:
GameObject::GameObject* gameobject = GameObject::getGameObject("player_gameobject");
window.draw(*gameobject->getSprite());
When i draw it texture is white.

22
Graphics / sprite.move() from my gameobject* is not working
« on: August 14, 2016, 03:04:12 pm »
Hello :). So i made gameobject class where is stored sprite and texture. So i when i try to move sprite from my gameobject* it's not moving (x value is not changing).

Graphics.cpp:
        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");

                        sf::Sprite sprite = gameobject->getSprite();

                        sf::Texture texture = gameobject->getTexture();
                       
                        sprite.setTexture(texture);

                        sprite.move(5, 0);

                        window.draw(sprite);

                        window.display();

                }

        }
GameObject.cpp:
#include "GameObject.h"
#include <unordered_map>

namespace GameObject {

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

        GameObject::GameObject() {

                name = "";

                sprite = sf::Sprite();

                texture = sf::Texture();

        }

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

                name = gameobject_name;

                sprite = gameobject_sprite;

                texture = gameobject_texture;

                sprite.setPosition(gameobject_position_x, gameobject_position_y);

        }

        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];
        }

}
And my GameObject class:
        class GameObject {

        private:

                std::string name;

                sf::Sprite sprite;

                sf::Texture texture;

        public:

                GameObject();

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

                void setName(std::string gameobject_name) {

                        name = gameobject_name;

                }

                void setSprite(sf::Sprite gameobject_sprite) {

                        sprite = gameobject_sprite;

                }

                void setTexture(sf::Texture gameobject_texture) {

                        texture = gameobject_texture;

                }

                std::string getName() {

                        return name;
                }

                sf::Sprite getSprite() {

                        return sprite;
                }

                sf::Texture getTexture() {

                        return texture;
                }

        };
I hope someone can help me  :). Thanks.
*UPDATE* i also tried gameobject->getSprite().move(3, 0); and nothing happens...

23
General / Is it possible to run the RenderWindow in the background?
« on: August 02, 2016, 07:43:54 pm »
Hello :), is it possible to run the RenderWindow thread in the background? If so, can anyone give me a simple code.

#include <SFML\Graphics.hpp>

sf::RenderWindow window;

void openWindow() {

        window.create(sf::VideoMode(800, 800), "Window");

        while (window.isOpen()) {

                sf::Event event;

                while (window.pollEvent(event)) {

                        switch (event.type) {

                        case sf::Event::Closed:

                                window.close();

                                break;
                        }

                }

        }

}
 

Thanks ;D.

24
So when i store sprite to map and get it back, texture disappears. Can someone tell me why is that happening  :-\.

Sprite.cpp:
#include <SFML\Graphics.hpp>

std::map<std::string, sf::Sprite> sprites;

void addSprite(std::string sprite_name, sf::Texture sprite_texture) {

        sf::Sprite sprite;

        sprite.setTexture(sprite_texture);

        sprites[sprite_name] = sprite;

}

sf::Sprite getSprite(std::string sprite_name) {

        sf::Sprite sprite = sprites[sprite_name];

        return sprite;
}
 

Game.cpp:
#include <iostream>
#include "Game.h"
#include "Window.h"
#include <thread>
#include "Resource.h"
#include "Sprite.h"

bool game_running = STOP;

void createGame() {

        openWindow();

        loadResources();

        startGame();

}

void loadResources() {

        //player

        sf::Texture player_texture = loadTexture("C:/Users/User/Desktop/resources/player_texture.png");

        addSprite("player_sprite", player_texture);

}
 

Window.cpp:
#include <SFML\Graphics.hpp>
#include <thread>
#include "Game.h"
#include "Resource.h"
#include "Sprite.h"

sf::RenderWindow window;

void openWindow() {

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

        sf::Sprite sprite_test = getSprite("player_sprite"); //there is no error here

        while (window.isOpen()) {

                sf::Event event;

                while (window.pollEvent(event)) {

                        switch (event.type) {

                        case sf::Event::Closed:

                                window.close();

                                break;
                        }

                }

                window.clear();
                window.draw(sprite_test); //and when i draw it nothing happens. There is even no white texture.
                window.display();

        }

}
 

I hope someone can help me, because i'm messing with this whole 2 days... :'(

Pages: 1 [2]
anything