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

Pages: 1 ... 11 12 [13] 14 15
181
SFML projects / Not Quite Pong
« on: July 26, 2008, 01:13:31 am »
It may just be me or my computer, but depending on the ball's speed the ball turns a shade of red. This is especially so in the executable with vertical sync. In the executable without vertical sync (where it's not so bad) the ball can turn almost completely red for a split second if I get it stuck between the side and my paddle.

Anyways, good work. I really like the flow. Now I just need a score system to prove to my buddy I just wiped the floor with him.

182
Graphics / Finding true Draw procedure/code for an OOP
« on: July 23, 2008, 11:39:43 am »
The way I have it is so that my list of sprites is a std::vector<sf::Drawable*>. However, using this method would mean that all your classes that you want to be drawn would need to be derived from sf::Drawable (sf::PostFX, sf::Shape, sf::Sprite and sf::String are already derived from sf::Drawable). Consider the following code:

Code: [Select]
#include <SFML/Graphics.hpp>


class Missile : public sf::Sprite
{
public :

    static bool Init(const std::string& image)
    {
        return m_Image.LoadFromFile(image);
    }

    Missile(const sf::Vector2f& position = sf::Vector2f(0.f, 0.f),
            const sf::Vector2f& scale = sf::Vector2f(1.f, 1.f),
            const float& rotation = 0.f,
            const sf::Color& col = sf::Color::White) :
            Sprite(m_Image, position, scale, rotation, col)
    {

    }

private :

    static sf::Image m_Image;
};

sf::Image Missile::m_Image;


std::vector<sf::Drawable*> g_Drawables;

int main()
{
    freopen("console.log", "w", stderr);

    if (!Missile::Init("images/missile.png"))
        return 1;

    sf::Event event;
    sf::RenderWindow window(sf::VideoMode(640, 480), "Tile",
                            sf::Style::Close,
                            sf::WindowSettings(0, 0));

    g_Drawables.push_back(new sf::Shape(sf::Shape::Circle(window.GetWidth() / 2U,
                                        window.GetHeight() / 2U, 16.f,
                                        sf::Color::Red)));
    g_Drawables.push_back(new Missile(sf::Vector2f(window.GetWidth() / 2U - 8U,
                                      window.GetHeight() / 2U - 32U)));

    for (;;)
    {
        while (window.GetEvent(event))
            if (event.Type == sf::Event::Closed)
            {
                for (std::vector<sf::Drawable*>::iterator it = g_Drawables.begin();
                        it != g_Drawables.end(); ++it)
                    delete *it;

                return 0;
            }

        for (std::vector<sf::Drawable*>::iterator it = g_Drawables.begin();
                it != g_Drawables.end(); ++it)
            window.Draw(**it);

        window.Display();
    }
}

It's a bit complicated, but you'll find it's an easy way to deal with a constantly changing number of drawables. If you wish certain drawables to be drawn on top of others you can either make sure that the drawable you want drawn on top is put on the list before the other drawables or you can even create a whole new layer/list of drawables.


I hope this helps!



P.S.: The call to freopen is just so we can report errors, it's nothing special. :)

EDIT: I just realized I didn't show you how to remove drawables! You can figure that out for yourself I guess. I'll try and get back to you if you need anything more though.

183
Graphics / Finding true Draw procedure/code for an OOP
« on: July 22, 2008, 11:56:29 pm »
Quote from: "fixus971"
is better a separated object that scan all, get sprite data and draw?

I've seen a lot of applications that do this and it would be acceptable by most standards, but I for one do not like the way it feels. Objects are meant for things that are declared multiple times.

Quote from: "fixus971"
Other option is to create a list of pointers to sprites of objects and pass that to main.draw

This is what I do in my applications. However, I do it so that my list of pointers are global. That way I can add sprites to the list from anywhere in my application. I also made inline helper functions called Create() and Remove() to make my hands happy.

184
General discussions / SFML 1.3 and OS X
« on: July 22, 2008, 06:31:37 am »
That's a shame. I can't help. I really do hope you find someone soon though. :(

185
Graphics / Finding true Draw procedure/code for an OOP
« on: July 22, 2008, 01:29:25 am »
I am not 100% sure if this is what you wanted, but here is a simplified version of how I create objects in my demos:

Code: [Select]
#include <SFML/Graphics.hpp>


class Missile : public sf::Sprite
{
public :

    static bool Init(const std::string& image)
    {
        return m_Image.LoadFromFile(image);
    }

    Missile() :
            Sprite(m_Image)
    {

    }

private :

    static sf::Image m_Image;
};

sf::Image Missile::m_Image;


int main()
{
    if (!Missile::Init("images/missile.png"))
        return 1;

    sf::Event event;
    sf::RenderWindow window(sf::VideoMode(640, 480), "Tile",
                            sf::Style::Close,
                            sf::WindowSettings(0, 0));

    Missile missiles[3];
    missiles[1].SetPosition(50, 50);
    missiles[2].SetPosition(40, 10);

    for (;;)
    {
        while (window.GetEvent(event))
            if (event.Type == sf::Event::Closed) return 0;

        window.Draw(missiles[0]);
        window.Draw(missiles[1]);
        window.Draw(missiles[2]);
        window.Display();
    }
}


Of course, you could use a vector instead of an array to easily add and remove missiles to the list of things that need to be drawn.

I hope this is what you needed!

186
Feature requests / sf::Drawable::GetPosition
« on: July 18, 2008, 10:55:16 pm »
There is a sf::Drawable::GetPosition method. :shock:

187
Feature requests / sf::Shape::Line arguments
« on: July 14, 2008, 07:57:58 am »
Does it really lead to cleaner code? I figured Vector2f was just for convenience when getting positions.

Setting positions via vectors, however, in my opinion, doesn't really provide much convenience other than when the position is from a get function.


For example, we could make lines that connect dots with this code:
Code: [Select]
sf::Shape circle1(sf::Shape::Circle(40, 40, 25, sf::Color(255, 255, 255)));
sf::Shape circle2(sf::Shape::Circle(600, 600, 25, sf::Color(255, 255, 255)));
sf::Shape line(sf::Shape::Line(circle1.GetPosition(), circle2.GetPosition(), 5, sf::Color(255, 255, 255)));


Rather than:
Code: [Select]
sf::Shape circle1(sf::Shape::Circle(40, 40, 25, sf::Color(255, 255, 255)));
sf::Shape circle2(sf::Shape::Circle(600, 600, 25, sf::Color(255, 255, 255)));
sf::Shape line(sf::Shape::Line(circle1.GetPosition().x, circle1.GetPosition().y, circle2.GetPosition().x, circle2.GetPosition().y, 5, sf::Color(255, 255, 255)));

188
Window / Bottleneck sf::Event
« on: July 11, 2008, 10:23:15 pm »
That is an interesting bug. I do not get it using the same setup with SFML 1.3.

189
Feature requests / sf::Shape::Line arguments
« on: July 11, 2008, 09:36:15 pm »
I don't see why we can't provide two versions...

In fact, I thought the whole point of Vector2f was to make the library feel cleaner, but the other function should be there for simplicity reasons.

190
Graphics / [Solved] SetCenter
« on: July 06, 2008, 07:49:54 pm »
So this was intentional?

Code: [Select]
mSprite.SetCenter(0.5f * theGlyph->Texture.GetWidth(), 0.5f * theGlyph->Texture.GetHeight());


I would think you would want to do this:

Code: [Select]
mSprite.SetCenter(0.5f * mSprite.GetSize().x, 0.5f * mSprite.GetSize().y);



Quote from: "Xylankant"
I don't know 1.2, but reading the documentation of 1.3, I'm not able to find GetWidth() or GetHeight() for either Sprites or Images. (What is what I expected, since I've never before used GetWidth()/Height() ...)

Did you try GetSize().x and GetSize().y? These Methods should give you the Height and Width!


GetWidth() does exist for sf::Image.


EDIT: I see you edited your post and I get it now. :P

So is SetSubRect() even needed?

191
Graphics / [Solved] SetCenter
« on: July 06, 2008, 07:41:48 pm »
The problem is you're getting the width of the image rather than the sprite. (which is a sub-rectangle of the image)

EDIT: Also, for consistency reasons, shouldn't sf::Image also use the GetSize method?

192
Feature requests / Clipboard Support
« on: July 05, 2008, 11:01:44 am »
I agree that this would be a valuable addition to SFML. In fact, I believe it is of above normal priority because of how beneficial this can be to so many different kinds of applications.

193
Network / Receive loop
« on: July 03, 2008, 01:46:52 am »
Quote from: "eleinvisible"
I use while(1)...Shortest way is the best way.


That's how I feel, but I use:

Code: [Select]
for (;;)


I do not care about semantics.

194
General discussions / SFML / Performance in VirtualBox
« on: July 01, 2008, 08:55:25 pm »
Alright, thanks for the info.

195
SFML wiki / [Tutorial] Manage dynamic key binding.
« on: July 01, 2008, 08:44:52 pm »
I think you should have included code for loading the keys from a file, but other than that it's a good tutorial to get someone thinking.

I'll probably use this as a reference when implementing this feature into my own applications. Thanks for a good tutorial, Mindiell.

Pages: 1 ... 11 12 [13] 14 15