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

Pages: [1]
1
General / Re: Book - CommandQueue
« on: July 26, 2015, 02:39:42 pm »
I actually don't have the book, I just analyzed the code on Github in order to have a better code architecture.

That is why I'm asking.

2
General / Book - CommandQueue
« on: July 26, 2015, 12:42:22 pm »
Hello !

I have a few questions about the CommandQueue class (related to Command and KeyBinding), classes extracted from the SFML book.

What is the utility of this class ? I thought it was in order to execute the actions in the right order (using the network), is that right ?

Otherwise, why do this instead of just using events (ie when we press space or the jump key, we call the jump method of the player) ?

Finally in KeyBinding we can see RealtimeActions. Is that actions which are repeated when the key isnt released, such as moving to the right when the key is pressed, on the contrary to an action like a jump or an attack which is called only once when the corresponding key is pressed ?

Thanks !

3
Graphics / How to handle views ?
« on: July 17, 2015, 03:31:09 pm »
Hello !

I'm wondering how to handle views so that I can always have the character at the center of the screen except when it approaches the border of the map.

My map is a tile-based vertexarray which is largest than the screen.

I wonder if I need to use one view for both the background and the character and center the view on the character (wouldn't it be jerky ?) or against the border of the map, OR two views, one for the background and one for the character (it would be positioned relatively to the screen) but it'd be complicated to calculate as I wouldn't have the absolute coordinates.

What's the right way to do it ?

Thanks !

4
Graphics / Book code - Custom draw
« on: July 11, 2015, 09:27:08 pm »
Hi guys!

With the code from the book, I tried to create a tiled map with vertex arrays (like there : http://www.sfml-dev.org/tutorials/2.3/graphics-vertex-array.php).

So I did this :

void World::buildScene()
{
        // Initialize the different layers
        for (std::size_t i = 0; i < LayerCount; ++i)
        {
                Category::Type category = (i == LowerAir) ? Category::SceneBackgroundLayer : Category::None;

                SceneNode::Ptr layer(new SceneNode(category));
                mSceneLayers[i] = layer.get();

                mSceneGraph.attachChild(std::move(layer));
        }

        // Prepare the tiled background
        sf::Texture& tilesetTexture = mTextures.get(Textures::Tileset);

    int roomHeight = 30;
    int roomWidth = 30;

    sf::VertexArray _vertices;
    _vertices.setPrimitiveType(sf::Quads);
    _vertices.resize(30 * 30 * 4);

        for(unsigned int y = 0; y < roomHeight; ++y)
        for(unsigned int x = 0; x < roomWidth; ++x)
        {
            unsigned int tileNumber = 5;
            unsigned int textureColumn, textureLine;

            textureColumn = (tileNumber % 30 == 0) ? 30 : tileNumber % 30;
            textureLine = (tileNumber % 30 == 0) ? tileNumber / 30 : tileNumber / 30 + 1;

            sf::Vector2u coordTexture;

            coordTexture.x = (textureColumn - 1) * (128  + 128);
            coordTexture.y = (textureLine   - 1) * (128 + 128);

            sf::Vertex* quad = &_vertices[(y * 30 + x) * 4];

            quad[0].position = sf::Vector2f(x * 128, y * 128);
            quad[1].position = sf::Vector2f((x + 1) * 128, y * 128);
            quad[2].position = sf::Vector2f((x + 1) * 128 , (y + 1) * 128);
            quad[3].position = sf::Vector2f(x * 128, (y + 1) * 128);

            quad[0].texCoords = sf::Vector2f(coordTexture.x, coordTexture.y);
            quad[1].texCoords = sf::Vector2f(coordTexture.x + 128, coordTexture.y);
            quad[2].texCoords = sf::Vector2f(coordTexture.x + 128, coordTexture.y + 128);
            quad[3].texCoords = sf::Vector2f(coordTexture.x, coordTexture.y + 128);
        }

    std::unique_ptr<SpriteNode> tiledBackground(new SpriteNode(tilesetTexture, _vertices));
    mSceneLayers[Background]->attachChild(std::move(tiledBackground));
}

And then I modified SpriteNode like that :

class SpriteNode : public SceneNode
{
        public:
                explicit                        SpriteNode(const sf::Texture& texture);
                                                        SpriteNode(const sf::Texture& texture, const sf::IntRect& textureRect);
                                                        SpriteNode(const sf::Texture& texture, sf::VertexArray& vertices);


        private:
                virtual void            drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const;


        private:
                sf::Sprite                      mSprite;
                sf::VertexArray     mVertices;
                sf::Texture         mTexture;
                bool                mTiled;
};

SpriteNode::SpriteNode(const sf::Texture& texture)
: mSprite(texture)
, mTiled(false)
{
}

SpriteNode::SpriteNode(const sf::Texture& texture, const sf::IntRect& textureRect)
: mSprite(texture, textureRect)
, mTiled(false)
{
}

SpriteNode::SpriteNode(const sf::Texture& texture, sf::VertexArray& vertices)
: mTexture(texture)
, mVertices(vertices)
, mTiled(true)
{
}

void SpriteNode::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const
{
        if(!mTiled)
        target.draw(mSprite, states);
    else
    {
        states.transform *= getTransform();
        states.texture = &mTexture;
        target.draw(mVertices, states);
    }
}
 

My VertexArray and my Texture are okay, the algorithm (with the 2 for) works in an other code but I'd like to integrate it into this one.

There, when I switch to GameState, I just see a black screen. What is wrong ?
I did put a std::cout in the else of the draw and it is displayed.

Thanks for your help!

Pages: [1]