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

Pages: 1 ... 4 5 [6] 7 8 9
76
Graphics / Re: camera in sfml 2.0
« on: June 25, 2012, 06:59:49 pm »
I've written a little demonstration with a bunch of graphic objects, using a view always centered on the player, so the player is always centered on the screen when he's moving.
I believe this is what you're trying to achieve, and as you can see this is quite easy to do:
1. move the player
2. set the view center as the player position

#include <SFML/Graphics.hpp>
#include <list>

void populate(std::list<sf::RectangleShape>& objects, float x, float y)
{
        sf::RectangleShape s(sf::Vector2f(20, 20));
        s.setPosition(x, y);
        s.setFillColor(sf::Color::Green);
        objects.push_back(s);
}

int main()
{
        sf::RenderWindow app(sf::VideoMode(480, 320), "view demo");
       
        // create player, at the screen center
        sf::RectangleShape player(sf::Vector2f(20, 20));
        player.setFillColor(sf::Color::Red);
        player.setOrigin(10, 10);
        player.setPosition(240, 160);
        const float player_speed = 100;

        // create a bunch of objects
        std::list<sf::RectangleShape> objects;
        populate(objects, 310, 50);
        populate(objects, 100, 200);
        populate(objects, 250, 160);
        populate(objects, 10, 280);
        populate(objects, 70, 30);
        populate(objects, 120, 50);

        // we create our custom view
        sf::View player_view(sf::FloatRect(0, 0, app.getSize().x, app.getSize().y));
       
        sf::Clock clock;
        bool running = true;
        sf::Event event;
        while (running)
        {
                while (app.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                running = false;
                }

                // moving player
                float frametime = clock.getElapsedTime().asSeconds();

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                        player.move(0, -player_speed * frametime);
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                        player.move(0, player_speed * frametime);
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                        player.move(-player_speed * frametime, 0);
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                        player.move(player_speed * frametime, 0);
       
                clock.restart();

                // we keep our view centered on the player
                player_view.setCenter(player.getPosition());
                app.setView(player_view);

                // rendering entities
                app.draw(player);
                for (std::list<sf::RectangleShape>::const_iterator it = objects.begin(); it != objects.end(); ++it)
                {
                        app.draw(*it);
                }
                app.display();
                app.clear();
        }
        app.close();
        return 0;
}
 

I hope everything is clear.

77
What are you trying to do? You're adding x-axis position, y-axis position, and scale factors, which doesn't make sense.
You can perform a simple collision test using bounding boxes:

1. build bounding boxes for your sprites, using FloatRect:
sf::FloatRect rect;
rect.Top = sprite.GetPosition().y;
rect.Left = sprite.GetPosition().x;
rect.Bottom = rect.Top + sprite.GetSize().y;
rect.Right = rect.Left + sprite.GetSize().x;
 

2. Test if two bounding boxes are overlapping:
if (rect.Intersects(rect2))
{
    // collision
}
 

78
General discussions / Re: Another python binding: python-sfml2
« on: June 04, 2012, 01:19:08 pm »
I know he is still working on his binding but I primarily maintain my own one because I don't want the same interface
What's wrong with the interface of Bastien's implementation?
Regarding the network module, Python already provides sockets and ftp library (but I bet you already know this).
Did you just want to copy the SFML API?

While I salute the initiative of enhancing the binding, I think a lot of users will be confused if two python bindings are proposed, especially since the both of them are up-to-date and look-alike.

79
General discussions / Re: New naming convention
« on: March 25, 2012, 04:23:43 pm »
That's the solution I'm currently using.
I was just assuming this may be part of the API, and I was pointing at position because I think this attribute is more used than the other ones you listed.
It would also avoid a couple of function calls, but I don't want to sound captious :)

80
General discussions / Re: New naming convention
« on: March 25, 2012, 01:06:03 pm »
Laurent, have you made up your mind about high-level getter/setter methods for sf::Transformable, such as getX, setX, getY, setY, getSize ?
IMHO, those methods would be really convenient, user code is sometimes too complex for really simple position manipulation.



81
Graphics / Collision with FloatRect
« on: February 22, 2012, 02:48:49 pm »
During the movement step, store the previous position of each object before computing its new position.
Then, in the collision detection step, if two objects are overlapping, assign their previous position (before collision), so you can ensure objects are never overlapping.

82
Feature requests / stay on top
« on: December 22, 2011, 12:43:10 pm »
This should be the user's choice, and you can already do that with your window manager.

83
General discussions / New graphics API ready
« on: December 20, 2011, 02:07:42 pm »
Great, it works fine. Thanks Laurent.

84
General discussions / New graphics API ready
« on: December 20, 2011, 01:40:46 pm »
Quote from: "Laurent"
Quote from: "Haze"
But if the line is neither vertical (A.x != B.x), nor horizontal (A.y != B.y), we must use trigonometry to compute the line length (rectangle width = distance between A and B), and then rotate the rectangle.

Yes. It's not a big deal.

So it doesn't worth creating a LineShape class?

I've also a couple of questions about the split Transformable/Drawable :

- In the previous graphics API, we were able to inherit from sf::Drawable in order to draw items relatively to the drawable position (I mean: positions of the items drawn in the overridden Render method were offset by the drawable's own position).

I cannot reproduce this behavior anymore (I've tested inheriting from Transformable - using my own Show method, and from Transformable + Drawable - using the overridden Draw method).
Is this feature still exist? If yes, how do I achieve this?

- Why don't you use a reference to pass the RenderStates object in the Drawable::Draw method?
Code: [Select]
virtual void Draw(RenderTarget& target, RenderStates states) const = 0;


Thanks

85
General discussions / New graphics API ready
« on: December 13, 2011, 05:33:30 pm »
Quote from: "Laurent"
If your line has a thickness, it's a rectangle and you can use sf::RectangleShape.

But if the line is neither vertical (A.x != B.x), nor horizontal (A.y != B.y), we must use trigonometry to compute the line length (rectangle width = distance between A and B), and then rotate the rectangle.

Quote from: "Laurent"
If it has no thickness, you can draw two vertices in sf::Lines mode.

I've played a bit with those primitive types, it's a nice feature :D
I will probably stick to this is solution when dealing with lines without thickness, I guess this is more optimized than using shapes.
But don't you think drawing a simple line should be more user-friendly than using primitive types?

86
General discussions / New graphics API ready
« on: December 13, 2011, 04:50:40 pm »
Quick question: now that sf::Shape::Line is gone, how can I easily draw a line from point A to point B ?

87
General discussions / New graphics API ready
« on: December 06, 2011, 04:48:47 pm »
What a fast replay, as always :)

Quote from: "Laurent"
Quote
I wish RectangleShape had a ctor which doesn't require a Vector2f object

Already discussed in previous pages ;)

Missed this request, my bad!

Quote
For consistency. I don't think it changes the user code significantly

Indeed that's really no big deal, I was just curious.

Quote
Basically, you can now write this:
Code: [Select]
window.Draw(sprite, sf::BlendNone);

Ok! It seems fine as well.

Quote
I tried to cleanup the API a little bit. There was too many functions in drawable entities.
Let's see if enough users want them back ;)

Oh, it wasn't that bloated, IMHO.
To be honest, I would even take it one step further and request some extra GetX / GetY methods...

88
General discussions / New graphics API ready
« on: December 06, 2011, 04:09:57 pm »
Hi, I've only tested the new API a few minutes, this is just an early feedback.

- I wish RectangleShape had a ctor which doesn't require a Vector2f object:
Code: [Select]
RectangleShape(float Width, float Height);

- Why did you rename sf::Blend::XYZ to sf::BlendXYZ?

- Where are the blend mode methods gone? (GetBlendMode/SetBlendMode)
Shouldn't they be implemented in sf::Drawable?

- I also miss several methods on transformable objects:
SetX, SetY, GetSize
Even if such operations can still be performed, I miss those higher-level methods, which I found convenient and avoid writing code like this:
Code: [Select]
sprite.SetPosition(42, sprite.GetPosition().y)

instead of:
Code: [Select]
sprite.SetPosition(42)

89
Feature requests / Window rendering and event processing in Windows
« on: December 05, 2011, 01:30:52 pm »
Eh, too bad.
Anyway, some user has found a workaround using threads:
http://www.sfml-dev.org/forum/viewtopic.php?t=5463

90
Feature requests / Window rendering and event processing in Windows
« on: December 05, 2011, 12:20:46 pm »
Quote from: "Laurent"
After looking at the MSDN, I found that this action (dragging or resizing the window) triggers a pair of events : WM_ENTERSIZEMOVE (when you click) and WM_EXITSIZEMOVE (when you release).

So, would it be possible to map these events to the SFML event system (something like sf::Event::WindowDragged) ?

Since rendering while dragging window seems impossible, developers could at least pause their application during dragging time and avoid getting an huge frametime when the user finally release the mouse button.

Pages: 1 ... 4 5 [6] 7 8 9