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

Pages: [1]
1
General discussions / Where can i get sprites/tiles?
« on: October 28, 2014, 09:45:38 am »
Hello everyone, as mentioned above, i'm wondering where can i find some tiles for my 2d game?
I found plenty sites but some ones offered only charakters and others only textures or whatever and they don't fit together.
I want to programm a RPG game or a jump an run, rather a RPG.
So, guys where i can find them, especially whole sets?

2
Graphics / Re: Line issue
« on: March 22, 2014, 11:07:00 am »
Well didn't know that, and thanks for explaining.

3
Graphics / Re: Line issue
« on: March 21, 2014, 11:01:51 pm »
Add 0.5 to the lines coordinates.

That works, thank you  :D

But why i have to do this? I thought a line is always 1 px thick as said in tutorial: http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php under sf::Lines

4
Graphics / [Solved]Line issue
« on: March 21, 2014, 10:21:32 pm »
I try myself on Vertexes.
I have wrote a class which have a rectangle inside and a border around.
The main porpose of the border to be kind of shadow around the box but that is not the problem.
When i display the border it have black lines like some lines is missing, and i make the border of lines(http://www.sfml-dev.org/documentation/2.1/classsf_1_1VertexArray.php)

In the first screenshot i have normal size window and there not so many black lines but in the second one maximized the window i got more of them.

code where i create the lines:

void Flat_Entity::create_border() //m_ is for member
{
            int points_count = m_border_thick*5;


            m_border.setPrimitiveType(sf::LinesStrip);
            m_border.resize(points_count);
            int increment_adress = 0; //increment for vector

            int x_near = m_x + m_border_thick;
            int y_near = m_y + m_border_thick;
            int x_far = m_x + m_width - m_border_thick;
            int y_far = m_y + m_height - m_border_thick;


            for(int size_thick = 0; size_thick < m_border_thick; ++size_thick) //size_thick represents px
            {
                    m_border[increment_adress++].position = sf::Vector2f(x_near-size_thick, y_near-size_thick); //for top-left corner
                    m_border[increment_adress++].position = sf::Vector2f(x_far+size_thick, y_near-size_thick);  //for top-right corner
                    m_border[increment_adress++].position = sf::Vector2f(x_far+size_thick, y_far+size_thick);   //for bottom-right corner
                    m_border[increment_adress++].position = sf::Vector2f(x_near-size_thick, y_far+size_thick);  //for bottom-left corner
                    m_border[increment_adress++].position = sf::Vector2f(x_near-size_thick, y_near-size_thick); //again for top-left, close the way
            }

            for(int i = 0; i < increment_adress; ++i)           //set color for border
                m_border[i].color = sf::Color(200, 150, 100);



}

thanks for help

6
Window / Re: Insert and remove text not working with Events
« on: February 10, 2014, 11:48:42 pm »
std::string &remove_last_char(std::string &text)
{
        text.erase(text.size() - 1, 1);
        return text;
}
 

EDIT: Looks like Jesper beat me to it!  :)
Yes thanks to both of you, helped me a lot :)

7
Window / Re: Insert and remove text not working with Events
« on: February 10, 2014, 11:46:43 pm »
text.erase(text.size(), 1);

If "text" contains "hello" then size() == 5, so the erase call would remove 1 character starting at position 5 (that is, string.end() - past the last char). I think you want text.erase(text.size() - 1, 1); offsets start at 0.
O that was easy, thanks it works.
I did have the same solution but with other event combination then i change that and the event, test it but forgot to chage the function back, my fault. ;) I do not know much about the String class in C++ because worked as always with char array and pointer in C :D

8
Window / Re: Insert and remove text not working with Events
« on: February 10, 2014, 11:22:25 pm »
So, same result?

I'd guess, then, that it could very well be something in the remove_last_char() and insert_last_char() functions.
Can we see those?  ;D
Sure :) here the whole code:
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>

#include <math.h>
#include <iostream>
#include <sstream>
//#include "include/Collision.h"

#define textsize 200


inline int give_letter_size(char &letter, sf::Font &font, int font_size)
{
    return font.getGlyph(int(letter), font_size, false).advance;
}

std::string &word_wrap(std::string &text, int width, int font_size, sf::Font &font)
{
    int s_width = 0;
    int last_word_position = 0;
    bool position_used = false;
    for(int i = 0; i <= text.size(); i++)
    {
        s_width += give_letter_size(text[i], font, font_size);

        if(s_width >= width)
        {
            if(!position_used)
            {
                text.replace(last_word_position, 1, "\n");
                i = last_word_position;
                position_used = true;
                s_width = 0;
            }
            else
            {
                text.insert(i, "\n");
                s_width = 0;
            }
        }
        if(text[i] == ' ')
        {
            last_word_position = i;
            position_used = false;
        }
    }
    return text;
}

std::string &remove_last_char(std::string &text)
{
    text.erase(text.size(), 1);
    return text;
}

std::string &insert_last_char(std::string &text, char char_)
{
    text.insert(text.size(), 1, char_);
    return text;
}

int main()
{
    sf::RenderWindow window(sf::VideoMode::getDesktopMode() , "SFML App", sf::Style::Default);

    sf::Font font;
    if(!font.loadFromFile("arial.ttf"))
        std::cout << "Schriftart konnte nicht geladen werden" << std::endl;


    std::string text = "Ich habe etwas zu programmieren, und das ist toll nicht wahr? Ich liebe es wenn etwas bei mir funktioniert. Das ist immer gut. sdfgsghdfhdrtzdfhgdfjhdgsdfgsdfgghfgdhghdgjhgfghjsdfgsgfhgfhhj";

    sf::Text showing_text;

    text = word_wrap(text, textsize, 20, font);

    showing_text.setString(text);

    showing_text.setCharacterSize(20);
    showing_text.setFont(font);
    showing_text.setPosition(0,0);
    showing_text.setColor(sf::Color::Red);

    std::string angaben = "Copyright by jakob, made for jakeos. Maybe the worst Solution that exist for SFML";

    angaben = word_wrap(angaben, textsize, 20, font);

    sf::Text show;
    show.setString(angaben);
    show.setCharacterSize(20);
    show.setFont(font);
    show.setPosition(1720, 500);
    show.setColor(sf::Color::Green);


    int width = showing_text.getGlobalBounds().width;

    std::cout << width << std::endl;

    //bool backspace = false;
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
            else if(event.type == sf::Event::TextEntered)
            {
                if(event.text.unicode != 0x00000008)
                {
                   insert_last_char(text, event.text.unicode);
                   showing_text.setString(text);
                }
            }
            else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::BackSpace)
            {
                remove_last_char(text);
                showing_text.setString(text);
            }

        }
        window.clear();
        window.draw(showing_text);
        window.draw(show);
        window.display();
    }

    return 0;
}
 

9
Window / Re: Insert and remove text not working with Events
« on: February 10, 2014, 11:00:21 pm »
Does it work the other way around:
if(event.text.unicode == 0x000008)
                {
                   remove_last_char(text);
                   showing_text.setString(text);
                }
                else
                {
                    insert_last_char(text, event.text.unicode);
                    showing_text.setString(text);
                }

Same thing, or a different result?
tried this before, most combinations unfortunately the same result: inputs works but can't remove.

10
Window / Re: Insert and remove text not working with Events
« on: February 10, 2014, 09:32:06 pm »
You should seriously just use a debugger and step through this. Coming here and saying "it doesn't work" doesn't give us any information. I am sure if you used a debugger you could very easily figure out why it isn't working properly.
and how it would be helping me?
my functions are ok i tested it, i think i handle the event wrong and thought you could help me.

Try this for your hex for backspace:
0x00000008
same thing

11
Window / Re: Insert and remove text not working with Events
« on: February 10, 2014, 07:21:05 pm »
As i wrote i tried some cases, this one isn't work either.

12
Window / Re: Insert and remove text not working with Events
« on: February 10, 2014, 05:12:27 pm »
How i can input and remove chars correctly?
This way i do it isn't working.
It accept char input but not going to third else if case, because it don't remove the char, don't execute remove_last_char(text); i think it is blocked by the if(event.text.unicode != 0x000008) statment but why.
Other ways isn't working also.

13
Window / [SOLVED]Insert and remove text not working with Events
« on: February 10, 2014, 03:13:15 pm »
Hello everyone.
I'm trying to catch inputs from keyboard and save it to a string and also to remove the last char with backspace.
I can't get it working, i tried many possible combinations but no one worked.
In my aktual try i filter the backspace out on TextEntered event but then it don't consider my action with backspace.
while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
            else if(event.type == sf::Event::TextEntered)
            {
                if(event.text.unicode != 0x000008)
                {
                   insert_last_char(text, event.text.unicode);
                   showing_text.setString(text);
                }
            }
            else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::BackSpace)
            {
                remove_last_char(text);
                showing_text.setString(text);
            }
        }

14
Graphics / Re: Set a defined size of textfield
« on: October 13, 2013, 05:53:48 pm »
If someone has the same problem, here is the solution: (maybe not a perfekt one  ;) ):

int give_letter_size(char &letter, sf::Font &font, int font_size)
{
    return font.getGlyph(int(letter), font_size, false).advance;
}

std::string &ready_text(std::string &text, int width, int font_size, sf::Font &font)
{
    int s_width = 0;
    int last_word = 0;
    for(int i = 0; i <= text.size(); i++)
    {
        if(s_width < width)
        {
            s_width += give_letter_size(text[i], font, font_size);
        }
        else
        {
            text.replace(last_word, 1, "\n");
            i = last_word;
            s_width = 0;
        }
        if(text[i] == ' ')
            last_word = i;
    }
    return text;
}
 

15
Graphics / [SOLVED]Set a defined size of textfield
« on: September 08, 2013, 11:25:21 pm »
Hello dear community. I have a problem which i tried to solve. I want define an area where sf::Text should be drawn with a constant size of the font, methods i've tried out:
count each character with a size of the font, when limit is reached insert newline "\n" isn't working because each character has diffirent size.
Draw each character with the font and then read the property width, very perfomance heavy and bad solvage, because each character in the line must be compared and add to the width at the line lenght, and this method isnt ready yet.
Well, maybe somebody knows a better method to do so.

sorry for bad english also  ;)

Pages: [1]