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

Pages: [1]
1
General / Re: Writing Unicode characters in sf::Text
« on: April 18, 2017, 04:51:11 pm »
Yeah, whole range I mean. So, I should check out the table https://en.wikipedia.org/wiki/Unicode_font ? And download ones with high number of Chars and Glyphs right ?


2
General / Writing Unicode characters in sf::Text
« on: April 17, 2017, 11:23:48 pm »
Hello, I want to be able to write all of this characters https://unicode-table.com/en/#latin-extended-a in my Text object.

I am having hard time and nothing is being successfull

What I've tried and doesn't work :

wchar_t c = L'\u2F00';

sf::Text my_text;
my_text.setString(c);
/*
... Rest of the setup for "my_text"
*/


 


When I draw it I just get a Square.

How to actually do this kind of stuff ?

3
General / Re: Weird memory usage
« on: April 02, 2017, 09:20:55 am »
@eXpl0it3r Can you give me an example how should I do it ?

I am already running it in release mode. My images are all 128x32, each of them use 1 KB of space.
So by doing this ((24bit * 128 * 32)/8)/(2 * 1024) I get the result 6MB ?

4
General / Weird memory usage
« on: April 02, 2017, 12:56:16 am »
I am curious why does my game use 80 MB of memory.

I am using VS 2015 and when I launch my game I see that my process memory is at 88 MB min.
Its weird. I am using like 30 textures 30 sprites.
In those 30 textures I load images from my folder called "images". These images all together use 80 KB.
All these textures are then loaded in my 30 sprites.

I create textures as pointers. This way :
sf::Texture* tx_wall = new sf::Texture();
tx_wall->loadFromFile("images/wall.bmp");

//MAIN GAME LOOP HERE
//.
//.
//.
// END OF GAME LOOP

delete tx_wall;

 

I also noticed that sometimes when I start game process memory jumps to 110 MB and stays at that point. If I launch my game again 3 times (sometimes only once) it goes back to 88 MB.

If I remove 4 images (They take 16 KB) from my folder so textures are not able to open them, it reduces my process memory by 20 MB so now my memory usage is 60 MB.

These 4 specific images only. If I remove any other image it Memory usage stays the same.
These images are only used by my custom class which look like this :

my_button.h
#pragma once
#ifndef MY_BUTTON_H
#define MY_BUTTON_H
       
#include <SFML\Graphics.hpp>


        class Button {
                private:
                        float x, y;
                        sf::RectangleShape size;
                        sf::Sprite *my_sprite;
                        sf::Texture *my_texture;
                        sf::Texture *my_press_texture;
                        bool me_pressed = false;
                public:
                       
                        Button(const sf::Texture& txr, const float& x_spawn, const float& y_spawn);
                        Button(const sf::Texture& txr,const sf::Texture& txr_p,  const float& x_spawn, const float& y_spawn);
                        ~Button();
                        sf::RectangleShape getSize();
                        sf::Vector2f getPosition();

                        void setPosition(const float& x_spawn, const float& y_spawn);

                        void setTexture(const sf::Texture& txr);
                        void setPressTexture(const sf::Texture& txr);
                       
                        void pressed(bool p);
                        bool is_pressed();
                        bool is_hovered(const sf::Vector2i& mouse_pos);

                        sf::Sprite getSprite();
        };


#endif
 

and this is the

my_button.cpp

#include "my_Button.h"

Button::Button(const sf::Texture& txr, const float& x_spawn, const float& y_spawn){
        x = x_spawn;
        y = y_spawn;

        my_sprite = new sf::Sprite(txr);
        my_texture = new sf::Texture(txr);

        my_sprite->setPosition(x, y);

        size.setSize(sf::Vector2f(my_sprite->getGlobalBounds().width, my_sprite->getGlobalBounds().height));
}

Button::Button(const sf::Texture& txr, const sf::Texture& txr_p, const float& x_spawn, const float& y_spawn) {

        x = x_spawn;
        y = y_spawn;
       
        my_sprite        = new sf::Sprite(txr);
        my_texture       = new sf::Texture(txr);
        my_press_texture = new sf::Texture(txr_p);

        size.setSize(sf::Vector2f(my_sprite->getGlobalBounds().width, my_sprite->getGlobalBounds().height));
}
Button::~Button() {
        delete my_sprite;
        delete my_texture;
        delete my_press_texture;
}

sf::RectangleShape Button::getSize() {
        return size;
}

sf::Vector2f Button::getPosition() {
        return sf::Vector2f(x, y);
}

void Button::setTexture(const sf::Texture& txr) {
        delete my_sprite;
        delete my_texture;
        my_texture = new sf::Texture(txr);
        my_sprite = new sf::Sprite(txr);
}

void Button::setPressTexture(const sf::Texture& txr) {
        my_press_texture = new sf::Texture(txr);
}

bool Button::is_hovered(const sf::Vector2i& mouse_pos) {
       
        if (my_sprite->getGlobalBounds().contains((float)mouse_pos.x, (float)mouse_pos.y)) {
                return true;
        }
        return false;
}

sf::Sprite Button::getSprite() {
        return *my_sprite;
}

void Button::setPosition(const float& x_spawn, const float& y_spawn) {
        x = x_spawn;
        y = y_spawn;

        my_sprite->setPosition(x, y);
}

void Button::pressed(bool p) {
        me_pressed = p;

        if (me_pressed) {
                my_sprite->setTexture(*my_press_texture);
        }
        else {
                my_sprite->setTexture(*my_texture);
        }
}

bool Button::is_pressed() {
        return me_pressed;
}

 


I have 2 buttons which use these 4 images (2x idle and 2x pressed). If I remove them memory goes down by 20 MB.

the 2 BUTTONS :

Button *cmd_continue = new Button(*texture_continue, popup_win.getPosition().x+16, popup_win.getPosition().y + popup_win.getSize().y - 48);
        Button *cmd_leave = new Button(*texture_leave, popup_win.getPosition().x + (popup_win.getSize().x - 16 - texture_leave->getSize().x), popup_win.getPosition().y + popup_win.getSize().y - 48);

        cmd_continue->setPressTexture(*texture_continue_p);
        cmd_leave->setPressTexture(*texture_leave_p);

//MAIN GAME LOOP DOWN THERE
 



And I have other 4 Buttons (my class). If I remove images from folder that they used for their textures Process MEMORY STAYS THE SAME.

What is happening here ? Any ideas ?

I am using :
VS 2015
WIN 10 x64
RAM 6GB
CPU Intel Core 2 Duo E8600
GPU AMD 5670HD 1 GB



Other variables I use they shouldn't take that much memory. My Map is presented in 2D char vector which is 39*50. That is 0,23 KB


If I do
sf::Texture::getMaximumSize()
this returns 16384

5
Graphics / Re: Blinking sprites, draw on click.
« on: March 26, 2017, 01:28:58 am »
Ok, thanks, but when I press the button again, the screen doesn't flick anymore.

6
Graphics / Blinking sprites, draw on click.
« on: March 26, 2017, 12:51:54 am »
Hello, I am trying to make better perfomance of my level editor a little better so while I am idle (not doing anything on window (pressing keys, spawning objects)) I want to draw the sprites to window and then wait for another click.

After I click again I want to spawn object on window, draw_everything_again(), win.display() but this causes blinking sprites. It actually draws them on correct places but they are blinking.


auto draw_map = [&win_editor] (const std::vector<std::vector<char>>& map, sf::Sprite wall_spr) {
                                                               
                                                                for (int i = 0; i < map.size(); i++) {
                                                                        //Go
                                                                        for (int j = 0; j < map[0].size(); j++) {
                                                                                if (map[i][j] == '*') {
                                                                                        wall_spr.setPosition(sf::Vector2f(i*gm_win.N, j*gm_win.N));
                                                                                        win_editor.draw(wall_spr);
                                                                                }
                                                                        }

                                                                }
                                                        };

bool btn_pressed = false;

while (win_editor.isOpen()) {
                                                               
  while (win_editor.pollEvent(some_events)) {
                                                                       
   //WINDOW IS OPENED
                                                                        switch (some_events.type) {

                                                                        case sf::Event::Closed:

                                                                                //Maybe ask for save safe;
                                                                                win_editor.close();

                                                                                break;
                                                                        case sf::Event::MouseButtonPressed:

                                                                                //Just perfomance stuff, we don't need to refresh window everytime, just when we do actions
                                                                                btn_pressed = true;
                                                                                break;
                                                                        }
                                                                       
                                                                       

                                                                       
                                                                } //End of while

                                                                if (btn_pressed) {
                                                                        win_editor.clear(sf::Color::Black);
                                                                        draw_map(editors_map, temp_spr);
                                                                        btn_pressed = false;
                                                                }

                                                                win_editor.display();
                                                        }
 


7
Yes. I get the value 16384. That just tells maximum size of the texture, and not how many textures could I use.

I want to know what is okay for project (e.g. you shouldn't use more than 10 textures with size equal to size that I get with sf::Texture::getMaximumSize() ) so I could take care of it in future.

8
Graphics / What is the limit of how many textures you should have ?
« on: March 16, 2017, 05:11:27 pm »
I've read in documentation that I shouldn't use too many textures... but I don't know how many of them do they mean.

I know that it depends on how big texture is as well, but still don't know what number of textures can be ok.

In my game I use around 10-15 Textures that are relatively small, 32x32 pixels and 1 of them is 256x512.
I am expecting answers : "Ohh no that's nothing... 32x32 pfff" but what if I use only big textures, is there anything that I should take care off ?


9
General / Re: The Snake game. Movement problem with clocks
« on: March 08, 2017, 11:44:10 pm »
Yeah, that's the problem (test it with increasing the delay value). I knew it was clock all along. Now I have to come up with new way of moving the snake to prevent this from happening.

EDIT:

Solved it !!!

It was pretty damn simple. I just added new public member "my_dir" inside snake class that is going to return a direction of snake.

left_pressed    = sf::Keyboard::isKeyPressed(sf::Keyboard::Left);
                        right_pressed   = sf::Keyboard::isKeyPressed(sf::Keyboard::Right);
                        down_pressed    = sf::Keyboard::isKeyPressed(sf::Keyboard::Down);
                        up_pressed              = sf::Keyboard::isKeyPressed(sf::Keyboard::Up);


                        keys_down               = (short)left_pressed + (short)right_pressed + (short)down_pressed + (short)up_pressed;


                        // MOVEMENT
                        if(keys_down==1){
                                if (left_pressed) {
                                        if (player.my_dir != Right)     dir = Left;
                                }
                                else if (right_pressed){
                                        if (player.my_dir != Left)      dir = Right;
                                }
                                else if (up_pressed) {
                                        if (player.my_dir != Down)      dir = Up;
                                }
                                else if (down_pressed) {
                                        if (player.my_dir != Up)        dir = Down;
                                }
                        }

                        // UPDATING SNAKE WITH DELAY TO REDUCE ITS SPEED
                        if (timer >= delay) {          
                                timer = 0;             
                                player.update();
                                //timer.restart();
                        }
 


SNAKE CLASS UPDATE FUNCTION

void update() {
                short   last_x = snake_tail[snake_tail.size() - 1].getPosition().x;
                short   last_y = snake_tail[snake_tail.size() - 1].getPosition().y;

                for (int i = snake_tail.size() - 1; i > 0; --i) {
                        snake_tail[i].setPosition(snake_tail[i - 1].getPosition().x, snake_tail[i - 1].getPosition().y);
                }
               
                 
                switch (dir)
                {
                        // Move snake

                case Left: //left
                        head_x -= N;
                        break;
                case Right: //right
                        head_x += N;
                        break;
                case Up: //up
                        head_y -= N;
                        break;
                case Down: //Down
                        head_y += N;
                        break;

                }
                my_dir = dir; // Here
                snake_tail[0].setPosition(head_x, head_y);
                short i = 0;

                .
                .
                .
 

Thank you Arcade !

10
General / The Snake game. Movement problem with clocks
« on: March 08, 2017, 03:22:51 pm »
Hello, I am new to SFML, I've read about everything I need to know that would get me ready for making this game.

I have successfully managed to create a game. The problem is with the movement.
I used isKeyPressed with left,up,down,right keys and I used clock to slowdown the snake. I also put some if statements to check whether the snake is moving eg. right when I press LEFT so it prevents snake doing 180 deg.

If you press 1 key at time when you want to move snake, everything works perfectly, but as soon as I press multiple keys ( I also created an if statement to check if player is holding multiple keys, if he is, then don't do anything if not, change direction) and start going crazy with it a little bit snake does 180 deg turn and its "GAME OVER".

Why does this happen ? I think my code is alright, but something happens that I have no idea what it is.

This is my MAIN LOOP

        sf::Clock       clock;
        float           timer = 0;
        float           delay = 0.1;

        bool    left_pressed    = false;
        bool    right_pressed   = false;
        bool    down_pressed    = false;
        bool    up_pressed      = false;

        // MAIN GAME LOOP ////////////////////////////////////////////////
        while (win.isOpen()) {

                // Setting up the clock
                float   time    = clock.getElapsedTime().asSeconds();

                clock.restart();
                timer += time;


                //Checking for events : closing, escape, enter
                while (win.pollEvent(event)) {
                        switch (event.type) {
                        case sf::Event::Closed:
                                win.close();
                                break;
                        case sf::Event::KeyReleased:
                                switch (event.key.code) {
                                case sf::Keyboard::Escape:
                                        win.close();
                                        break;
                                case sf::Keyboard::Return:
                                        game_state = state_of_game::PLAYING;
                                        player.respawn();
                                        break;
                                default:
                                        break;
                                }
                               
                        default:
                                break;
                        }
                }
&#273;

                // CHECK IF YOU ATE YOURSELF //

                if (game_state == state_of_game::LOST) {

                        sf::Text        lost("GAME OVER", font, 100U);

                        lost.setFillColor(sf::Color::Red);

                        lost.setPosition(win_w / 2 - lost.getCharacterSize() * 3, win_h / 2 - lost.getCharacterSize());
                        win.draw(lost);

                }
                else {

                        left_pressed    = sf::Keyboard::isKeyPressed(sf::Keyboard::Left);
                        right_pressed   = sf::Keyboard::isKeyPressed(sf::Keyboard::Right);
                        down_pressed    = sf::Keyboard::isKeyPressed(sf::Keyboard::Down);
                        up_pressed      = sf::Keyboard::isKeyPressed(sf::Keyboard::Up);


                        keys_down = (short)left_pressed + (short)right_pressed + (short)down_pressed + (short)up_pressed;


                        // MOVEMENT
                        if(keys_down==1){
                                if (left_pressed) {
                                        if (dir != Right)       dir = Left;
                                }
                                else if (right_pressed){
                                        if (dir != Left)        dir = Right;
                                }
                                else if (up_pressed) {
                                        if (dir != Down)         dir = Up;
                                }
                                else if (down_pressed) {
                                        if (dir != Up)   dir = Down;
                                }
                        }

                        // UPDATING SNAKE WITH DELAY TO REDUCE ITS SPEED
                        if (timer >= delay) {          
                                timer = 0;             
                                player.update();
                        }

                        //Clear the window with color WHITE
                        win.clear(sf::Color::White);

                        /////// Draw everything here ///////////
                        //win.draw(...);
               
                        // Draw lines
                        //win.draw(d_bgr);
                       

                        //Draw the snake
                        for (int i = 0; i < player.get_size(); i++) {
                                win.draw(player[i]);
                        }
               
                        // Draw the goal
                        win.draw(v_goal.draw());


                        //Draw the wall
                        for (int i = 0; i < wall_vec.size(); i++) {
                                wall_sprite.setPosition(wall_vec[i][0], wall_vec[i][1]);
                                win.draw(wall_sprite);
                        }
                }

                //end of frame
                win.display();
        }


 

This is my update function in object player.

void update() {
                short   last_x = snake_tail[snake_tail.size() - 1].getPosition().x;
                short   last_y = snake_tail[snake_tail.size() - 1].getPosition().y;

                for (int i = snake_tail.size() - 1; i > 0; --i) {
                        snake_tail[i].setPosition(snake_tail[i - 1].getPosition().x, snake_tail[i - 1].getPosition().y);
                }
               
                 
                switch (dir)
                {
                        // Move snake

                case Left: //left
                        head_x -= N;
                        break;
                case Right: //right
                        head_x += N;
                        break;
                case Up: //up
                        head_y -= N;
                        break;
                case Down: //Down
                        head_y += N;
                        break;

                }

                snake_tail[0].setPosition(head_x, head_y);
                short i = 0;
               

                for (i = 1; i < snake_tail.size(); i++) {
                        get_x = snake_tail[i].getPosition().x;
                        get_y = snake_tail[i].getPosition().y;

                        if ( get_x == head_x && get_y == head_y) {
                                game_state = { LOST };
                        }
                }
                if (game_state != LOST){
                // CHECK IF SNAKE HIT THE WALL

                        if (head_x == 0)                                game_state = LOST;
                        else if (head_x == win_w - 16)  game_state = LOST;
                        else if (head_y == 0)                   game_state = LOST;
                        else if (head_y == win_h - 16)  game_state = LOST;
                }

                // Check if goal is at that position
                if(game_state!=LOST)
                if (v_goal.x == head_x && v_goal.y == head_y) {
                        // Increase size
                        for (i = 0; i < v_goal.increase; i++) {
                                snake_tail.push_back(snake_sprite);
                                snake_size++;
                                snake_tail[snake_tail.size() - 1].setPosition(last_x, last_y);
                        }                      

                        // RESPAWN THE GOAL
                        v_goal.respawn(snake_tail);
                }
               
        }
 


Sorry if I didn't explain it well (the problem). Game is working, but sometimes when I press 2 keys at once it does the 180 turn, but sometimes I go really crazy and start pressing 3 keys and try everything and it works normally and it comes back again.

What might cause this ? Any ideas ?

Pages: [1]
anything