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

Pages: [1]
1
General / Drawing layers - only with OpenGL?
« on: March 16, 2013, 03:43:04 pm »
Hey there!

I'm not sure how to ask this question, but is there a way to draw 'in layers' in SFML 2.0 without using OpenGL? What I mean by this is for example drawing a tree on a tile map in a way that it will always be on top, no matter in what order do I render things. I think this is pretty much what the depth buffer in OpenGL does, but I'm trying to avoid having to use it. So is there a built-in way of doing this?

2
General / Re: How to copy a sprite 2+ times over the screen?
« on: February 25, 2013, 02:11:33 am »
Move your sprite, draw it on the window, move it again and draw it again.

Or use the same sf::Texture for 2 different sf::Sprite, each with its own position (and rotation etc.), and draw both of them.
Do not hesitate to use multiple sprites when needed, they are inexpensive. Just don't duplicate textures.

Thanks you for the quick answer!

3
General / [RESOLVED] How to copy a sprite 2+ times over the screen?
« on: February 25, 2013, 01:49:14 am »
Hey guys!

I am new to SFML (coming from SDL), and I have to say I'm very impressed! But I have some trouble adapting my way of thinking to SFML 2.0 and I just cannot figure out this one.

How do I render a sprite more than once at different positions on the screen (like you can with SDL_Surface)? I want to use sprites because they allow easy adaptation to any screen size through sf::Sprite::setScale.

I'm really not sure how to go about it.

4
Graphics / Re: SFML 2.0 flip question
« on: February 25, 2013, 12:43:16 am »
Your new left should be "left + width", or something like that.

Thanks, I have no idea why I didn't realize that!

5
Graphics / Re: SFML 2.0 flip question
« on: February 25, 2013, 12:29:01 am »
Use getTextureRect() instead of getLocalBounds(), width and height are always positive in bounds so -width is always negative.

Now the sprite turns invisible instead of simply not turning back when I flip the second time.

6
Graphics / SFML 2.0 flip question [SOLVED]
« on: February 24, 2013, 10:16:47 pm »
Hey guys!

I found a forum post explaining how to flip a sprite in SFML 2.0, but it doesn't seem to be working well in my game and I can't find where I went wrong. The problem is, it only flips the sprite once and it won't ever flip it back to original. Here is the code:

// The flip function works well
void Flip(sf::Sprite& sprite)
{
        sprite.setTextureRect(
                sf::IntRect(
                        sprite.getLocalBounds().width,
                        0,
                        -sprite.getLocalBounds().width,
                        sprite.getLocalBounds().height
                )
        );
}

while (window.isOpen())
{
        vector.x = 0;
        vector.y = 0;

        // Input
        while (window.pollEvent(event))
        {
                // ...
        }

        // Same thing with the right key, you get the idea
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
                vector.x -= 7;

                if (direction != LEFT)
                {
                        direction = LEFT;
                        Flip(sprite);
                }
        }

        // ...

        sprite.setTexture(
                spriteAnimTextures[spriteAnim.GetCurrentFrame()]
        );
}

Now, as I said, after the first flip to the right, it stops working. What might be the error here?

Pages: [1]