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

Pages: 1 ... 3 4 [5] 6
61
SFML projects / Re: SFGUI (0.0.0 released)
« on: January 09, 2013, 01:28:54 am »
Hi, I'm having some trouble learning the API with the documentation alone. Where can I get some additional example code other than Hello, World!?

62
Quote
It's just that I don't like unnecessary copies if I can avoid it
I think it's wrong to think this way. You do copies all the time, and I'm sure you don't notice most of them. And they are not unnecessary; or if you think so, then maybe you should work with an assembly language rather than one that provides abstractions ;)

And, of course, "I don"t like" alone is never an argument. I can't build a library based on what one user likes or not. I need strong arguments. I'm sure you understand that :P
Really? I don't make copies all the time. I try to use pass-by-ref all the time if it's not fundamental types. And there are copies that are absolutely unnecessary(sf::Vector2f in my case). This is why STL provides emplace functions.

And what about inconsistency? I of course thought that sf::RectangleShape::setSize() took 2 float arguments because other functions such as setPosition() and setOrigin() took 2 arguments and wondered why my compiler gave me error. So I thought there was another error in my code searched for the error in my code for 5 minutes. And then I checked the doc and found out that it only takes a Vector.
Inconsistency causes confusions to users. Users shouldn't have to keep in mind that some functions only take a vector and some functions take 2 separate arguments. A simple API should be consistent throughout.

63
Quote
This seems inconsistent with other functions in SFML.
sf::Shape::setPosition(), sf::Shape::setScale(), sf::Shape::setOrigin(),  sf::Shape::move(), and other functions have overloads for taking 2 separate arguments.
But why not sf::Rect::setSize()?
Quote from: Laurent
Functions that have overloads taking separate floats are there mainly for historical reasons.

Quote
Other than "ugliness", I can avoid unnecessary copies of sf::Vector2f object
What's wrong with copying sf::Vector2?
It's just that I don't like unnecessary copies if I can avoid it

64
Quote
I think there's no reason for this not to be implemented.
The reason is to avoid duplicating a big amount of functions. In my opinion, "ugliness" is not a valid argument for it.
Functions that have overloads taking separate floats are there mainly for historical reasons.
This seems inconsistent with other functions in SFML.
sf::Shape::setPosition(), sf::Shape::setScale(), sf::Shape::setOrigin(),  sf::Shape::move(), and other functions have overloads for taking 2 separate arguments.
But why not sf::Rect::setSize()? ??? This doesn't seem like "duplicating" functions.
Other than "ugliness", I can avoid unnecessary copies of sf::Vector2f object

65
I think there's no reason for this not to be implemented.

sf::Rect<T> has a constructor overload that takes 4 arguments instead of 2 vector arguments..
STL containers also provide emplace_back(args..)

66
I see that sf::RectangleShape::setSize() only takes a sf::Vector2f object.
Can you make an overload that takes 2 float arguments?

It's kind of looking ugly in my code to construct a temorary Vector2f

67
Graphics / Re: Switching in between backgrounds
« on: January 06, 2013, 05:24:12 pm »
I see a problem with you using rand()
Use this method below..
int rand(int low, int high){return std::rand () % (high - low + 1) + low;}

case 0: //Case introstate
            randBackgroundNum = rand() % 5; //get a number 0 - 5
            break;
        case 1: //Case historystate
            randBackgroundNum = rand() % 10 + 6; //get a number 6 - 10
            break;

So above should be
randBackgroundNum=rand(0, 5);
randBackgroundNum=rand(6, 10);

68
Maybe you can update or get a new machine?
It'll be worth it.

69
Window / Re: Mouse Button Event not triggering
« on: January 04, 2013, 04:30:55 pm »
Poll the event only once, not every time you need to. So only one sf::Event object is needed.

You can change this part :
if(sStartBnRec.contains(localPosition.x,localPosition.y))
        {
            sStartBn.setTexture(tStartBn_hl);
            while(window.pollEvent(eMouseClk))
            {
                if (eMouseClk.type == sf::Event::MouseButtonPressed)
                {
           
                    if(eMouseClk.mouseButton.button == sf::Mouse::Left)
                    {
                        nCurrentScene=2;
                    }
                }
            }
        }
 

to
if(sStartBnRec.contains(localPosition.x,localPosition.y))
{
   sStartBn.setTexture(tStartBn_hl);
   if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Right)
          nCurrentScene=2;
}

70
SFML wiki / Re: sfeMovie project [v1.0 RC1 available]
« on: January 04, 2013, 04:22:13 pm »
Did anyone successfully compiled sfeMovie for Visual Studio 2012?

VS 2010 binary worked fine for me

71
General / Re: A crash in my button class
« on: January 02, 2013, 05:10:49 am »
I edited my code so that it uses boost::signal
But the crash still occurs
class Button
{
private:
        sf::Text text;
        boost::signal<void()> onEnter;
        boost::signal<void()> onExit;
        boost::signal<void()> onClick;
        void update(sf::RenderWindow & window);
public:
        Button(const char * string, sf::Font & font, sf::Color color, sf::Vector2f position, unsigned int size);
        ~Button();
        sf::Text & getText(){return text;}
        void draw(sf::RenderWindow & window);
        void connect(std::function<void()>  onEnter, std::function<void()>  onExit ,std::function<void()> onClick);
};
 

#include "Button.h"
#include <SFML/Window.hpp>

Button::Button(const char * string, sf::Font & font, sf::Color color, sf::Vector2f position, unsigned int size):text(string, font, size)
{
        text.setColor(color);
        text.setPosition(position);
}

Button::~Button()
{
}

void Button::update(sf::RenderWindow & window)
{
        sf::Vector2i mousePos=sf::Mouse::getPosition(window);
        float x1=text.getGlobalBounds().left;
        float x2=x1+text.getGlobalBounds().width;
        float y1=text.getGlobalBounds().top;
        float y2=y1+text.getGlobalBounds().height;
        if(x1<=mousePos.x && mousePos.x<=x2 && y1<=mousePos.y && mousePos.y<=y2)
        {
                (onEnter)();
                if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
                        (onClick)();
        }
        (onExit)();
}

void Button::connect(std::function<void(void)> onEnter, std::function<void(void)>  onExit,  std::function<void(void)>  onClick)
{
        this->onEnter.connect(onEnter);
        this->onExit.connect(onExit);
        this->onClick.connect(onClick);
}

void Button::draw(sf::RenderWindow & window)
{
        update(window);
        window.draw(text);
}

Weird thing is that even if I don't call update() or window.draw(), my program still crashes when the Button destructor gets called...

Here's how I'm using my button class
button=new Button("Hello, World!", font(), sf::Color::Black, sf::Vector2f(100, 100), 40);
        button->connect([&](){button->getText().setCharacterSize(50);},
                                        [&](){button->getText().setCharacterSize(40);},
                                        [&](){std::cout<<"YOU CLICKED ME\n!";});

72
General / A crash in my button class
« on: January 02, 2013, 04:08:27 am »
Here's my button class
#include <SFML/Graphics.hpp>
#include <functional>

class Button
{
public:
        static void init(sf::RenderWindow & window);
private:
        static sf::RenderWindow * window;
        sf::Text text;
        std::function<void(void)>  onEnter;
        std::function<void(void)>  onExit;
        std::function<void(void)>  onClick;
public:
        Button(const char * string, sf::Font & font, sf::Color color, sf::Vector2f position, unsigned int size);
        ~Button();
        sf::Text & getText(){return text;}
        void draw();
        void update();
        void connect(std::function<void(void)>  onEnter, std::function<void(void)>  onExit ,std::function<void(void)>  onClick);
};
#include "Button.h"
#include <SFML/Window.hpp>

sf::RenderWindow * Button::window =nullptr;

void Button::init(sf::RenderWindow & window_)
{
        window=&window_;
}

Button::Button(const char * string, sf::Font & font, sf::Color color, sf::Vector2f position, unsigned int size):text(string, font, size)
{
        text.setColor(color);
        text.setPosition(position);
}

Button::~Button()
{
}

void Button::update()
{
        sf::Vector2i mousePos=sf::Mouse::getPosition(*window);
        float x1=text.getGlobalBounds().left;
        float x2=x1+text.getGlobalBounds().width;
        float y1=text.getGlobalBounds().top;
        float y2=y1+text.getGlobalBounds().height;
        if(x1<=mousePos.x && mousePos.x<=x2 && y1<=mousePos.y && mousePos.y<=y2)
        {
                (onEnter)();
                if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left))
                        (onClick)();
        }
        else
               (onExit)();
}

void Button::connect(std::function<void(void)> onEnter, std::function<void(void)>  onExit,  std::function<void(void)>  onClick)
{
        this->onEnter=onEnter;
        this->onExit=onExit;
        this->onClick=onClick;
}

void Button::draw()
{
        window->draw(text);
}
 

crash occurs in Button::draw() method.
Is there something wrong with my code?

73
SFML projects / Re: sfeMovie Project [v1.0 released]
« on: December 31, 2012, 04:40:04 pm »
Thank you, everything is working fine now.

74
SFML projects / Re: sfeMovie Project [v1.0 released]
« on: December 31, 2012, 05:14:13 am »
Hi Ceylo !
I'm new to the SFML and trying to run this sfeMovie project to my Visual Studio project.The problem i get is with the creation of the FFmpeg.I followed the provided instructions but every thing crashes on the last step in the minGW.
I'm running the file build.sh but for some reason i get the strange message that ffmped-sourse directory is missing.
Where should i put it or what i can do to generate the ffmpeg libs
What did you do and what is the error you get?

Hi, I'm also getting the same error
I did the exact same thing as instructed on the website.

I launched mingw shell and typed ./build.sh windows in the sfeMovie directory
Then it gave me couple options and selected visual studio 2010
Then it gives that error

By the way I'm using VS 2012, will VS 2010 version work fine for VS 2012?

75
SFML projects / SFML Resource Wrapper (Update)
« on: November 10, 2012, 04:18:34 am »
I think someone already put something similar to this, but I wanted to share.
I wrote a simple resource wrapper for sf::Texture, sf::Music, sf::Font and sf::Sound
This does reference counting so that you will never load a same resource twice
Download it here:https://sourceforge.net/projects/kiwongames/files/SFML%20resource%20wrapper/

Update: 1.1
Added FontResource.
Fixed internal design using templates and inheritance. But no change in public interface.

There are 4 Resource classes.
Each of them has a static manager class to manage the resources.
But to make this simple, I made the manager class private, so you don't have any access to the manager class. (The manager's constructor is private too)
  • MusicResource-wrapper for sf::Music
  • SoundResource-wrapper for sf::Sound
  • TextureResource-wrapper for sf::Texture
  • FontResource-wrapper for sf::Font

There are only 2 things you need to know to use these
-constructor
-get()

Constructor
Each resource constructor takes one std::string argument for the name of the resource
ex) MusicResource music("music.wav");

get()
Each resource object has get() method for retrieving your resource
  • TextureResource::get() returns a reference to sf::Sprite. This sprite is binded to a sf::Texture object
  • MusicResource::get() returns a reference to sf::Music.
  • SoundResource::get() returns a reference to sf::Sound. This sound is binded to a sf::SoundBuffer object
  • FontResource::get() returns a reference to sf::Font.

Below is a sample code to show you how easy it is to use Simple Resource Wrapper for SFML

#include "MusicResource.h"
#include "SoundResource.h"
#include "TextureResource.h"


int main()
 {
     // Create the main window
     sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
 
     // Load a sprite to display
        TextureResource texture1("Pretty_Image.png");
        TextureResource texture2("Pretty_Image.png");//This won't load Pretty_Image.png twice.
        texture2.get().setRotation(10); //change rotation

        //Load a third texture to display
        TextureResource texture3("Even_Prettier.png");
        texture3.get().setPosition(100, 100);//change position
 
     // Load a music to play
        MusicResource music("good_music.wav");
        //play the music
        music.get().play();

        //Load a font
        FontResource font("C:/Users/Park/Desktop/Resources/Bedizen.ttf");
        sf::Text text("Hello", font.get());
        sf::Text text2("World", font.get());
        text2.move(400, 0);
 
     while (window.isOpen())
     {
         sf::Event event;
         while (window.pollEvent(event))
         {
             if (event.type == sf::Event::Closed)
                 window.close();
         }
         window.clear();
 
         // Draw the first texture
         window.draw(texture1.get());
         // Draw the second texture
         window.draw(texture2.get());
         // Draw the third texture
          window.draw(texture3.get());
         //draw the texts
         window.draw(text);
         window.draw(text2);
         window.display();
     }
        //load a short sound for finale
        SoundResource sound("Bye_Bye.wav");
       
        //Play the bye bye sound
        sound.get().play();
     return EXIT_SUCCESS;
 }

 

Pages: 1 ... 3 4 [5] 6
anything