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

Pages: 1 2 [3] 4 5 ... 15
31
Graphics / Re: Having trouble black lines with tilemaps - again
« on: August 25, 2014, 01:10:43 pm »
In here
Code: [Select]
void Player::move(const sf::Vector2f& offset)
    {
        m_sprite.move(offset);
        SceneManager::getView().setCenter(m_sprite.getPosition());
    }

//This line
SceneManager::getView().setCenter(m_sprite.getPosition());
//Make it this
SceneManager::getView().setCenter(sf::Vector2f( std::floor(m_sprite.getPosition().x), std::floor(m_sprite.getPosition().y) ) );
I am pretty sure your are the same guy in last topic. We discussed this already. make view positions a whole number without decimal point.

Read about std::Floor here http://en.cppreference.com/w/cpp/numeric/math/floor

32
Graphics / Re: Drawing a click and drag rectangle?
« on: August 25, 2014, 01:06:55 pm »
General idea:
When Mouse button left pressed, save position as start position, until Mouse button left released, calculate:
If start position X < mouse X, Draw rectangle from mouse X to start position x else draw from start position X to mouse X
Do same logic for Y axis and you got yourself the math complete now implement it using sfml. Good luck!

33
Graphics / Re: How to make sf::RenderTexture i can manipulate
« on: August 25, 2014, 12:00:44 am »
also,
"Fish, buy free fish!"
don't make your shopkeepers sell fish for free, or they'll profit nothing :P
Rad hint  ;D
That is so stupid, i cannot believe i wrote that.

34
Graphics / Re: How to make sf::RenderTexture i can manipulate
« on: August 24, 2014, 09:50:38 pm »
Yeah it would cost allot of process, in that case just making texture per text.
Also there should be 5-6 dialogs with 10-30characters and 1-2 with 50-100. At certain times when game cannot lag.

So the general purpose is to have it is for dialog in rpg. While walking trough town to see dialog people are talking. shop keepers screaming "Fish, buy free fish!". Also it is supposed to work in battle when there process is tight.
Well im still open for suggestion if you got good idea, if not. I will probably keep it low with text :)

35
Graphics / Re: How to make sf::RenderTexture i can manipulate
« on: August 24, 2014, 09:28:00 pm »
Is there replacement for renderTexture that is stored in RAM and i can manipulate? instead of using renderTexture.

36
Graphics / How to make sf::RenderTexture i can manipulate
« on: August 24, 2014, 09:04:54 pm »
Hello.
I have idea: I want to draw text on screen but keep it efficient, so draw text onto renderTexture then use VertexArray to draw it on screen so save performance is the general idea.

But i am facing one thing, i cannot manipulate render texture, for example i want to delete part of it(making it transparent so i can put another text there).
Any ideas how to clear part of renderTexture.

This is how i drawn the text via vertexArray using renderTextures
Code: [Select]
int main()
{
sf::View view;
//view.setCenter(sf::Vector2f(400, 300));
view.setViewport(sf::FloatRect(0, 0, 1, 1));

sf::RenderWindow win;
sf::VideoMode vidMod(800,600,32);
win.create(vidMod, "hello", sf::Style::Default);
win.setFramerateLimit(100);
win.setView(view);

sf::RenderTexture renTex;
sf::Text txt;
sf::Font font;
sf::RectangleShape rec;
sf::VertexArray verArr;

font.loadFromFile("arial.ttf");

txt.setCharacterSize(24);
txt.setColor(sf::Color::Black);
txt.setFont(font);
txt.setString("Greeting young traveler!\nMay i be of any assistence?");
txt.setPosition(-txt.getLocalBounds().left, -txt.getLocalBounds().top);
sf::FloatRect tfr = txt.getLocalBounds();

rec.setPosition(-tfr.left, -tfr.top);
rec.setSize(sf::Vector2f(tfr.width + tfr.left, tfr.height + tfr.top*2));

renTex.create(tfr.width + tfr.left, tfr.height + tfr.top);
renTex.draw(txt);
renTex.display();

verArr.setPrimitiveType(sf::Quads);
for (int i = 0; i < 1; i++)
{
std::cout << " x:" << renTex.getSize().x << " y:" << renTex.getSize().y << std::endl;
verArr.append(sf::Vertex(sf::Vector2f(i, 0), sf::Color(255, 255, 255, 255), sf::Vector2f(0, 0)));
verArr.append(sf::Vertex(sf::Vector2f(i + renTex.getSize().x, 0), sf::Color(255, 255, 255, 255), sf::Vector2f(renTex.getSize().x, 0)));
verArr.append(sf::Vertex(sf::Vector2f(i + renTex.getSize().x, renTex.getSize().y), sf::Color(255, 255, 255, 255), sf::Vector2f(renTex.getSize().x, renTex.getSize().y)));
verArr.append(sf::Vertex(sf::Vector2f(i, +renTex.getSize().y), sf::Color(255, 255, 255, 255), sf::Vector2f(0, renTex.getSize().y)));
}
sf::RenderStates renSta;
renSta.texture = &renTex.getTexture();

bool done = false;
while(done == false)
{
win.clear();

sf::Event event;
while(win.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
done = true;
break;
case sf::Event::KeyPressed:
switch(event.key.code)
{
case sf::Keyboard::K:
break;
default:
break;
}
break;
default:
break;
}
}
win.draw(rec);
//win.draw(spr);

win.draw(verArr, renSta);
win.display();
}

return 0;
};

37
Graphics / Re: Having trouble black lines with tilemaps - again
« on: August 20, 2014, 08:36:24 pm »
http://s26.postimg.org/3u9y594nd/Example.png
All fine in example, post example picture please.

38
SFML projects / Re: F.I.R.E.D. v0.99.pre-alpha
« on: August 18, 2014, 08:26:26 pm »
Question: How do the stats affect you? i saw "strength" is there a melee combat?

39
SFML projects / Re: The Wanderer - Lost in time
« on: August 18, 2014, 08:18:51 pm »
Update 2.
Done inventory, and the change is final.
Merged objects and units intro a single "thing" now called objects,
Some animations(Art is from http://opengameart.org) i cannot specify artist directly, i got it long time ago decided to use it.
Here is a video : https://www.youtube.com/watch?v=yQNwskaJaxk
For some reason i couldn't get my Fraps to do longer video them 30 sec, i will be switching recoding program for next video, till then cya!

We are still working hard, each day.
By the way, still need a pixel artist.

40
General / Re: isKeyPressed() vs event checking
« on: August 17, 2014, 02:24:42 am »
This belongs in discussion not help.
No! The "General Discussion" is about general stuff. BeautiCode is looking for help on his question and thus it belongs to the Help section. Please don't make such suggestions if you don't fully understand how Laurent has setup the sub-forums. ;)
I strictly believe he asked for discussion with this:
Which do you guys think is better? Checking to see if the user has pressed a key in your event loop, or just calling isKeyPressed() in your main loop?
But the other part is a question, which i know too little to be called an expert, so i wouldn't miss inform him.
Are there any performance benefits to either, besides being able to check if 2 keys are pressed at once?
From http://en.sfml-dev.org/forums/index.php?topic=5559.0"Read before posting"
I quote Laurent: "A lot of people end up posting in the wrong forum, and this can be irritating for admins. Moreover, people may not read your post if it's at the wrong place".
I was hasty, i analysed the post incorrectly and assumed there is no question  :'( i am sorry BeautiCode!

41
General / Re: isKeyPressed() vs event checking
« on: August 16, 2014, 10:08:07 pm »
Which do you guys think is better? Checking to see if the user has pressed a key in your event loop, or just calling isKeyPressed() in your main loop? Are there any performance benefits to either, besides being able to check if 2 keys are pressed at once?
This belongs in discussion not help.EDIT:: :o
Its all explain in the tutorials and documentation, i suggest reading those.
BTW each one has its own benefits and downfalls.

42
General / Re: Make old text dissappear and new appear in sf::Text
« on: August 16, 2014, 10:04:49 pm »
How bad is your opinion about me? :P
What is that supposed to mean? You don't know basics he was just noting something important.
But if he knew the ball was actually moving, he could observe there is no trail of ball movement  8)

EDIT::
This operator<< is appending data
http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/
Code: [Select]
std::stringstream convert1(std::string("Content");
std::stringstream convert2(std::string("");
//Doing following operation
convert1 << (int)moveSpeed; //moveSpeed of the ball
convert2 << (int)moveSpeed; //moveSpeed of the ball
//Lead to convert1 and conver2 look like
conver1.str == "Content1";
conver2.str == "1";
You can use .str() instead of operator<<
Code: [Select]
std::stringStream S;
s.str() = std::string((int)moveSpeed); //moveSpeed of the ball
Another suggestion, use std::to_string
Code: [Select]
int i = 999888;
std::string str = std::to_string(i);//str would be "999888"

43
EDIT:: i never thanked you for the knowledge, thank you!

Humm... a efficient way would be to have a sf::Texture intro which i want to draw text on, then from there i use sf::VertexArray to get texture coordinates to draw it. Efficiently have one draw call.
Issues: Managing the sf::Texture size, and content.

Question: Is it possible to clear area of render texture with RGB(0,0,0,0) ? because i want to reuse its position for new text that will be drawn
Figured out.

Also doing "sf::Texture::getMaximumSize()" returned 16384, is that pixel amount? 1D max size?
I googled, its per dimension if somebody wonders...

44
Hello.
I am making : http://en.sfml-dev.org/forums/index.php?topic=14563.0
Working on conversation between units, i want to make floating text that will be used for:
"Long text ~30 to 100char", "battle numbers(heal,damage,effect, battle shouts)", "Hints", "NPC conversation and player to npc conversation".
So to assume there should be 500char worth of text on screen at a same time(at specific time not alwais), i was wondering if anybody did testing with sf::Text to render texture to render window or sf::Text to render window?

And generally to ask, any better ideas then just doing sf::Text and drawing at location?

45
Graphics / Re: Line artifacts when drawing tilemap
« on: August 10, 2014, 06:00:52 pm »
Ok, here's the entirety of all of my relevant code:

Player.hpp

class Player : public Entity
        {
        public:
                typedef std::shared_ptr<Player> Ptr;

                static Ptr create(const std::string& id = "player") { Ptr temp(new Player(id)); return temp; }

                void handleCollision();

                void move(const sf::Vector2f& offset);

                virtual void update(sf::Time dt);

                void draw(sf::RenderTarget& target, sf::RenderStates states) const;

        private:
                Player(const std::string& id = "player", bool active = true);

                sf::Texture m_texture;
                sf::Sprite m_sprite;

                sf::Vector2f m_viewArea;

                bool nextPosValid(const sf::Vector2f& offset);
                bool rectOverlapsTile(const sf::FloatRect& rect);
        };

Player.cpp

        Player::Player(const std::string& id, bool active) :
                m_viewArea(sf::Vector2f(100, 100))
        {
                m_texture.loadFromFile("Resources/player.png");
                m_sprite.setTexture(m_texture);
                m_sprite.setPosition(350, 300);

                registerAttribute("renderable", new bool(true));
                registerAttribute("health", new int(20));

                SceneManager::getView().setCenter(std::floor(350), std::floor(300));
                SceneManager::getView().setSize(m_viewArea);
        }

        bool Player::nextPosValid(const sf::Vector2f& offset)
        {
                sf::Vector2f offsettedPos(std::floor(m_sprite.getPosition().x + offset.x), std::floor(m_sprite.getPosition().y + offset.y));

                //The bounding rectangle of the future player
                sf::FloatRect rect(offsettedPos, sf::Vector2f(std::floor(m_sprite.getGlobalBounds().width), std::floor(m_sprite.getGlobalBounds().height)));

                if (SceneManager::getWorld().getCurrentCell()->getTileMap().collidesWithType(2, rect))
                        return false;

                return true;
        }

        void Player::move(const sf::Vector2f& offset)
        {
                m_sprite.move(offset);
                SceneManager::getView().move(offset);
        }

        void Player::update(sf::Time dt)
        {
                if (InputManager::isActive(User_Input::UPHOLD))
                {
                        if (nextPosValid(sf::Vector2f(0, -100 * dt.asSeconds())))
                                move(sf::Vector2f(0, -100 * dt.asSeconds()));
                }

                if (InputManager::isActive(User_Input::LEFTHOLD))
                {
                        if (nextPosValid(sf::Vector2f(-100 * dt.asSeconds(), 0)))
                                move(sf::Vector2f(-100 * dt.asSeconds(), 0));
                }

                if (InputManager::isActive(User_Input::DOWNHOLD))
                {
                        if (nextPosValid(sf::Vector2f(0, 100 * dt.asSeconds())))
                                move(sf::Vector2f(0, 100 * dt.asSeconds()));
                }

                if (InputManager::isActive(User_Input::RIGHTHOLD))
                {
                        if (nextPosValid(sf::Vector2f(100 * dt.asSeconds(), 0)))
                                move(sf::Vector2f(100 * dt.asSeconds(), 0));
                }

                if (InputManager::isActive(User_Input::PPRESS))
                {
                        getAttribute<int>("health") -= 5;

                        std::cout << "Player health is now: " << getAttribute<int>("health") << std::endl;
                }

                if (InputManager::isActive(User_Input::VHOLD))
                {
                        if (SceneManager::getView().getSize().x < 300 ||
                                SceneManager::getView().getSize().y < 300)
                                SceneManager::getView().setSize(sf::Vector2f(SceneManager::getView().getSize().x + 0.5, SceneManager::getView().getSize().y + 0.5));
                }

                else if (InputManager::isActive(User_Input::IHOLD))
                {
                        if (SceneManager::getView().getSize().x >= 100 ||
                                SceneManager::getView().getSize().y >= 100)
                                SceneManager::getView().setSize(sf::Vector2f(SceneManager::getView().getSize().x - 0.5, SceneManager::getView().getSize().y - 0.5));
                }

                if (getAttribute<int>("health") <= 0)
                        setAttribute("renderable", new bool(false));

                setPosition(m_sprite.getPosition());
                setBounds(m_sprite.getGlobalBounds());
        }

        void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
                target.draw(m_sprite, states);
        }

Tilemap.hpp

        class TileMap : public sf::Drawable, public sf::Transformable
        {
        public:
                struct Tile
                {
                        Tile(const sf::FloatRect& bounds, int tileType) : bounds(bounds), tileType(tileType) {};

                        sf::FloatRect bounds;
                        int tileType;
                };

                void load(const std::string& tileSet, sf::Vector2u tileSize, int* tiles,
                        unsigned int width, unsigned int height)
                {
                        m_tileset.loadFromFile(tileSet);

                        m_vertices.setPrimitiveType(sf::Quads);
                        m_vertices.resize(width * height * 4);

                        for (unsigned int i = 0; i < width; ++i)
                        {
                                for (unsigned int j = 0; j < height; ++j)
                                {
                                        int tileNumber = tiles[i + j * width];

                                        sf::Vector2f topLeft(i * tileSize.x, j * tileSize.y);
                                        sf::Vector2f topRight((i + 1) * tileSize.x, j * tileSize.y);
                                        sf::Vector2f downLeft((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                                        sf::Vector2f downRight(i * tileSize.x, (j + 1) * tileSize.y);

                                        sf::FloatRect rect(topLeft.x, topLeft.y, topRight.x - topLeft.x, downLeft.y - topLeft.y);

                                        Tile tile(rect, tileNumber);

                                        m_tiles.push_back(tile);

                                        //Find the position in the tileset texture
                                        int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
                                        int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);

                                        sf::Vertex* quad = &m_vertices[(i + j * width) * 4];

                                        //Define its 4 corners
                                        quad[0].position = sf::Vector2f(std::floor(topLeft.x), std::floor(topLeft.y));
                                        quad[1].position = sf::Vector2f(std::floor(topRight.x), std::floor(topRight.y));
                                        quad[2].position = sf::Vector2f(std::floor(downLeft.x), std::floor(downLeft.y));
                                        quad[3].position = sf::Vector2f(std::floor(downRight.x), std::floor(downRight.y));

                                        //Define its 4 texture coordinates
                                        quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                                        quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                                        quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                                        quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
                                }
                        }
                }

                bool collidesWithType(int tileType, const sf::FloatRect& bounds)
                {
                        for (auto& iter : m_tiles)
                        {
                                if (iter.tileType == tileType)
                                {
                                        if (bounds.intersects(iter.bounds))
                                                return true;
                                }
                        }

                        return false;
                }

        private:
                virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
                {
                        states.transform *= getTransform();
                        states.texture = &m_tileset;
                        target.draw(m_vertices, states);
                }

                sf::VertexArray m_vertices;
                sf::Texture m_tileset;

                std::vector<Tile> m_tiles;
        };

As you can see, I tried using std::floor on my views and my tiles, but unfortunately nothing has been working so far.

You bumped... i repeat "Post minimal example that reproduces the error." i don't have time to waste going trough random code.
Meaning, you create a main function and you add intro it ONLY the things you need help with, make it compile and post the code, we will fix it for you.
By doing this you will most likely fix the mistake yourself.

EDIT:: also please, if you want to fix the error, post your specs, os, also did you update gpu drivers?

Pages: 1 2 [3] 4 5 ... 15
anything